when I have running the below code I have got error message

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 Comment

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.

Sign in to comment.

 Accepted Answer

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 Comments

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
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!