フィルターのクリア

Need a command as simple things sir

1 回表示 (過去 30 日間)
VIJAY
VIJAY 2017 年 12 月 11 日
コメント済み: KL 2017 年 12 月 11 日
  • 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
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;

Jan
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

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by