Here is my problem:
I have a nxn
matrix in matlab. I want to delete all the zeros of this matrix and put the rows of it in vectors. For n=4
, let say I have the following matrix:
A = [ 1 1 0 0
1 2 0 0
1 0 0 0
1 2 1 0 ];
How to get the following:
v1 = [ 1 1 ];
v2 = [ 1 2 ];
v3 = [ 1 ];
v4 = [ 1 2 1 ];
I did the following:
for i = 1:size(A, 1)
tmp = A(i, :);
tmp(A(i, :)==0)=[];
v{i} = tmp;
end