randperm

14 次查看(过去 30 天)
Miriam
Miriam 2011-11-11
How can I use randperm for a nx2 matrix?
  1 个评论
Dr. Seis
Dr. Seis 2011-11-11
"randperm" only takes 1 scalar input argument. Can you give a sample of an input nx2 matrix AND what you would expect the output to be?

请先登录,再进行评论。

回答(3 个)

Jonathan
Jonathan 2011-11-11
If you want to randomly permute the rows, do something like the following.
n = 5;
A = reshape(1:2*n, n, 2)
B = A(randperm(n), :)
If you want to randomly permute all elements, do something like this instead.
C = reshape(A(randperm(2*n)), n, 2)
  1 个评论
Jonathan
Jonathan 2011-11-11
@Miriam, to permute the columns separately do this.
D = A;
D(:,1) = D(randperm(n),1);
D(:,2) = D(randperm(n),2);

请先登录,再进行评论。


Miriam
Miriam 2011-11-11
I see, hmm.. actually I wanted to permute the two columns seperately, but I guess this will not work with randperm. But the suggestions were very helpful anyway! Thanks!

Jan
Jan 2011-11-11
You can use FEX: Shuffle:
A = rand(100, 2);
Dim = 1;
B = Shuffle(A, Dim);

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by