MATLAB: Is it possible to generate a set of numbers within a range chosen from a random array

arrayrandomrange

My problem lies in the last line. I want to generate a set of numbers within the range corresponding to 1:10 from the random array of R.
R = rand(length(U),1);
[B,I] = sort(R);
R1 = totalarray(I,:);
P1 = sort(R1(:,10));

Best Answer

If you want to extract the numbers in the range 0-10 from the 10th column of R1, then do this:
col10 = R1(:, 10);
rowsToExtract = col10 >= 0 & col10 <= 10;
extractedNumbers = col10(rowsToExtract)
If you want to extract the numbers in the range 0-10 from anyplace in R1, then do this:
elementsToExtract = R1 >= 0 & R1 <= 10;
extractedNumbers = R1(rowsToExtract) % will be a 1-D vector.