matrix with different randperm rows
28 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jeremy
am 17 Sep. 2014
Kommentiert: Jeremy
am 18 Sep. 2014
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 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 17 Sep. 2014
Bearbeitet: Andrei Bobrov
am 17 Sep. 2014
[~, out] = sort(rand(M,N),2);
3 Kommentare
Weitere Antworten (3)
Guillaume
am 17 Sep. 2014
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 Kommentare
Mikhail
am 17 Sep. 2014
4 Kommentare
Image Analyst
am 17 Sep. 2014
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
am 17 Sep. 2014
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 Kommentar
Joseph Cheng
am 17 Sep. 2014
Bearbeitet: Joseph Cheng
am 17 Sep. 2014
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).
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!