Prev: 3D face recognition
Next: Saving as .mat vs .m
From: Anthony on 11 Jun 2010 13:57 Hey, I'm having trouble transforming this matrix. I want to reshape and then add stuff to it. I've done it manually so you can see what it looks like, but I'd like to use an instruction instead of doing it manually. A is a 10x3 matrix. I need to turn it into a 3x9 B (dropping the first row of A) as follows: A = rand(10,3); A1 = A(2:4,:); A2 = A(5:7,:); A3 = A(8:10,:); B = [A1 A2 A3]; Once that`s done I need to add two 3x3 identity matrices along "diagonals" which aren't really diagonals and zeros elsewhere. So the final matrix should be a 9x9: B(4:9,:) = 0; B(4:6,1:3) = eye(3,3); B(7:9,4:6) = eye(3,3); So B should look like this: B = [A1 A2 A3; I 0 0; 0 I 0] I hope this clear, my apologies if its super trivial, I'm still getting used to matrix manipulation. Thanks Anthony
From: Matt Fig on 11 Jun 2010 14:32 Why not just use a simple little FOR loop? C = diag(ones(1,6),-3); for ii = 1:3:7 C(1:3,ii:ii+2) = A(ii+1:ii+3,:); end
|
Pages: 1 Prev: 3D face recognition Next: Saving as .mat vs .m |