when I have running the below code I got the following message
*??? Error using ==> randperm
Too many input arguments.*
The code is
locations_per_FACT = 4;
number_of_types = 4;
number_of_locations = 13;
population_size = 100;
for K = population_size : -1 : 1
FACT(K) = struct('location', randperm(number_of_locations,locations_per_FACT), 'type', randi(number_of_types,1,locations_per_FACT), 'rate', rand(1,locations_per_FACT));
end

1 件のコメント

Geoff Hayes
Geoff Hayes 2015 年 10 月 17 日
omer - this error message is telling you that are trying to pass too many input arguments into the http://www.mathworks.com/help/matlab/ref/randperm.html function. I can run the above code without any problems (using R2014a) so perhaps your version of MATLAB doesn't support the two arguments. In the Command Window, type
help randperm
What does the help show you? Does it show that you can pass one or two arguments? My help shows
randperm Random permutation.
P = randperm(N) returns a vector containing a random permutation of the
integers 1:N. For example, randperm(6) might be [2 4 5 6 1 3].
P = randperm(N,K) returns a row vector containing K unique integers
selected randomly from 1:N. For example, randperm(6,3) might be [4 2 5].
etc.

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

 採用された回答

Walter Roberson
Walter Roberson 2015 年 10 月 18 日

0 投票

Sufficiently old versions of randperm did not support two arguments. The replacement for
C = randperm(A,B)
in that case is
T = randperm(A);
C = T(1:B);

3 件のコメント

omer Elsiddig
omer Elsiddig 2015 年 10 月 18 日
Dear Mr. Walter
Accordingly you may modify the below code:
locations_per_FACT = 4; number_of_types = 4; number_of_locations = 13; population_size = 100; for K = population_size : -1 : 1 FACT(K) = struct('location', randperm(number_of_locations,locations_per_FACT), 'type', randi(number_of_types,1,locations_per_FACT), 'rate', rand(1,locations_per_FACT)); end
Walter Roberson
Walter Roberson 2015 年 10 月 18 日
Accordingly you can learn enough matlab to modify it yourself. I have shown you the pattern and you have seen enough matlab code that the basics are not a mystery to you.
We are not here to do everything for you. We teach you and you use the information to do the work yourself.
omer Elsiddig
omer Elsiddig 2015 年 10 月 18 日
Thank you Walter

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Mathematics についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by