Use numbers in a matrix to call vector row
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Christopher
am 30 Sep. 2014
Beantwortet: Michael Haderlein
am 30 Sep. 2014
I have the code
prand = rand(100,100);
P = 1+round(prand*999);
P2 = P(samparray,1); % this part doesn't work
where samparray is a 1000x1 array of numbers
So we have a matrix P of randomly generated integers (between 1 and 1000). Each number in P corresponds to a row in samparray, and I want P2 to return the corresponding values in samparray into the form of matrix P. How can I modify P2 to do this?
Thanks
0 Kommentare
Akzeptierte Antwort
Michael Haderlein
am 30 Sep. 2014
P2=P(samparray);
should work.
1+round(prand*999) isn't the best way to get randomly distributed integers between 1 and 1000 as the probability of 1 and 1000 (the limits) is lower than for the other values. Better would be 1+fix(prand*1000) or randi(1000,100,100).
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!