How to select two matrices randomly from a set of N matrices and then randomly select a few rows from first selected matrix and then exchange with corresponding rows of other selected matrix.
1 次查看(过去 30 天)
显示 更早的评论
For example we have 10 matrices A,B,C,D,E,F,G,h,I,J and we select randomly two matrices C and H. And then Randomly select any two rows from C and exchange with corresponding rows of H.
0 个评论
回答(2 个)
Andrei Bobrov
2016-10-25
For the case where the matrices have the same size:
Q = cat(3,A,B,C,D,E,F,G,H,I,J);
ii = [3,8] % C and H
n = size(Q,1);
z = 1:n;
jj = z(randperm(n,2));
M = Q(:,:,ii);
M(jj,:,:) = M(jj,:,end:-1:1);
Q(:,:,ii) = M;
2 个评论
Thorsten
2016-10-25
z = 1:n;
jj = z(randperm(n,2));
is the same as
jj = randperm(n,2);
And you don't need the temporarily variable M but can work directly on Q.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!