Need a command as simple things sir
1 次查看(过去 30 天)
显示 更早的评论
- 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????????????
回答(2 个)
Walter Roberson
2017-12-11
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 个评论
Jan
2017-12-11
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!