hai i need a command for following details........
1 次查看(过去 30 天)
显示 更早的评论
Here i am using the following command
as
>> randperm(12,4)
>> 1 3 8 12
In above command the maximum value is 12 for this command.
How can i set the the limit of randperm command ie the result should be as the range of 2 to 12???????????
the answer may be as
>>2 5 6 7........
1 个评论
Jan
2017-12-11
Please post one thread per problem only. See: https://www.mathworks.com/matlabcentral/answers/372244-need-a-command-as-simple-things-sir
采纳的回答
Birdman
2017-12-11
One approach:
while true
a=randperm(12,4)
if max(a)>7
else
break;
end
end
更多回答(2 个)
Walter Roberson
2017-12-11
"s it possible to create an array by using this command(randsample(2:12,4)) for example the array size is 7*4 etc etc...???????"
[~,temp] = sort(rand(7, 11), 2);
result = 1 + temp(:,1:4));
The range 2 to 12 is achieved by taking the range 1 to 11 and adding 1 to that.
The random ordering is done by sorting random numbers by rows. This method of sort() is what randperm it self used to use.
1 个评论
Jan
2017-12-11
randperm uses the sorting of a random vector only, if it is called with 1 input. For 2 inputs I assume the faster Fisher-Yates-Shuffle is applied (at least randperm(n,n) is much faster than randperm(n) - enhancement request was sent already).
Nevertheless, randperm(11, 4) + 1 is an easy solution also, but must be called in a loop.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!