Need a command as simple things sir
1 view (last 30 days)
Show older comments
- Any array size example of 5*4 or 7*8 etc.......
- No repeated value in a row only .
- Integer as a whole value and also it should be within range example 2 to 12
- Above all condition must be satisfied................................
Example result:
m=[2 4 6 12 3 5 9 10 4 5 7 8]
I collected commands as follow >>randperm(12,4) this command whole integer value & Non repeated value in row but cannot set a minimum range as 2 but can set maximum range as 12
>>randsample(2:12,4) This command satisfied all the things except cannot create an array only.It creats a single row
Is there any command creat an array by using randsample which should satisfied my condition????????????
Answers (2)
Walter Roberson
on 11 Dec 2017
numrows = 5;
numcols = 4;
range_min = 2;
range_max = 12;
range_span = range_max - range_min + 1;
[~, temp] = sort( rand(numrows, range_span), 2);
output = temp(:, 1:numcols) + rand_min - 1;
0 Comments
Jan
on 11 Dec 2017
minV = 2;
maxV = 12;
a = zeros(5, 4);
for k = 1:5
a(k, :) = randperm(maxV - minV + 1, 4) + minV - 1;
end
Or:
minV = 2;
maxV = 12;
V = minV : maxV;
nV = length(V);
a = zeros(5, 4);
for k = 1:5
a(k, :) = V(randperm(nV, 4));
end
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!