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

我将首先创建一个函数,该函数返回一个只有三行的子矩阵,它将一个整数作为三行中的第一行。然后我会做这样的事情:

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