creating array of random integer elements without repetition

hello ...
i want to create two diminsion array with random integer numbers without repetitions. i used (rand) but its not useful for me and also utilized (randperm) but it cont returen array with two diminsion , anybody have better solutions
thanks:)
Positions=rand(3,6);
Positions =
0.3587 0.3888 0.1338 0.5000 0.8110 0.6735
0.5236 0.6166 0.5943 0.3471 0.4452 0.5193
0.3926 0.4391 0.6673 0.0145 0.2968 0.9036
Positions=randperm(6,6);
Positions =
5 3 2 4 1 6

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 11 月 7 日

1 投票

You can reshape the randperm()
array_size = [3 6];
n = prod(array_size);
Positions = reshape(randperm(n), array_size)

2 件のコメント

ahmed noori
ahmed noori 2020 年 11 月 7 日
thanks that was so useful
Ameer Hamza
Ameer Hamza 2020 年 11 月 8 日
I am glad to be of help!!!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2020 年 11 月 7 日

コメント済み:

2020 年 11 月 8 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by