Problem 641. Make a random, non-repeating vector.
解决方案Stats
Problem Comments
解决方案Comments
-
1 Comment
nice!
-
2 Comments
好问题
好问题
-
1 Comment
randperm(n);
-
1 Comment
thanks for the clue at description
-
1 Comment
vec = randperm(n);
-
1 Comment
该解决方案似乎在MATLAB(台式机)中正确运行...有人可以告诉我为什么它会以“断言失败”回来?
函数vec = makerandomOrdering(n)
vec = zeros(1, numel(n));
flags = zeros(1, numel(n));
索引= 1;
while(sum(flags)〜= numel(n))
pos = randi(numel(n));
if (flags(pos) ~= 1)
vec(index) = n(pos);
索引=索引 + 1;
标志(pos)= 1;
end
end
end
Problem Recent Solvers5196
建议的问题
Maximum running product for a string of numbers
1481 Solvers
Number of 1s in the Binary Representation of a Number
解决384
Convert a numerical matrix into a cell array of strings
874 Solvers
677 Solvers
1131 Solvers
来自作者的更多51
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
开始狩猎!