Filter löschen
Filter löschen

Need a command as simple things sir

1 Ansicht (letzte 30 Tage)
VIJAY
VIJAY am 11 Dez. 2017
Kommentiert: KL am 11 Dez. 2017
  • 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????????????

Antworten (2)

Walter Roberson
Walter Roberson am 11 Dez. 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;

Jan
Jan am 11 Dez. 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

Kategorien

Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by