好问题
randperm(n);
thanks for the clue at description
vec = randperm(n);
该解决方案似乎在MATLAB(台式机)中正确运行...有人可以告诉我为什么它会以“断言失败”回来?
function 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;
flags(pos) = 1;
end
end
end