matrix with different randperm rows
13 次查看(过去 30 天)
显示 更早的评论
Hi,
Say I have vector of N integers, 1 through N. Is there a quick way, without loops, to create a matrix where each row is a different randperm of the vector? My N can get large (up to 100).
Thanks
0 个评论
采纳的回答
更多回答(3 个)
Guillaume
2014-9-17
cell2mat(arrayfun(@(dummy) randperm(n), 1:m, 'UniformOutput', false)');
Whether or not that can be said to be without a loop is debatable as arrayfun is effectively looping over the array 1:m
0 个评论
Mikhail
2014-9-17
4 个评论
Image Analyst
2014-9-17
In what universe, or decade, is 100 considered large? You actually mean 100, right, like ten times ten, not 100 million or 100 billion or something?
Joseph Cheng
2014-9-17
Well there is a randperm() function that will give you a random permuation. How to get it as a MxN matrix without a loop will take some more time to think about it.
1 个评论
Joseph Cheng
2014-9-17
编辑:Joseph Cheng
2014-9-17
ok well it is possible to do it without a loop in 2ish lines. Use the function arrayfun() or cellfun() on an array of N*ones(M,1).
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!