0

I have two m*n matrices, A and P. I want to randomly choose the same 3 rows from both matrices, e.g. rows m, m+1, m+2 are picked from both matrices. I want to be able to make the calculation U=A-P on the selected subset (i.e. Usub-Psub), rather than before the selection. So far I have only been able to select rows from one matrix, without being able to match it to the other. The code I use for this is:

A=[0,1,1,3,2,4,4,5;0,2,1,1,3,3,5,5;0,3,1,1,4,4,2,5;0,1,1,1,2,2,5,5]

P=[0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0]

U=A-P

k = randperm(size(U,1));

Usub = U(k(1:3),:);

4

1 に答える 1

0

最初に、3 つの行の最初の行として整数を取る 3 つの行しか持たない部分行列を返す関数を作成します。それから私はこのようなことをします:

m = number of rows;
randomRow = rand() % m;
U = A.sub(randomRow) - P.sub(randomRow);
于 2012-04-18T17:31:41.943 に答える