필터 지우기
필터 지우기

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 CenterFile Exchange에서 Introduction 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