one of the solutions
m=[
1 0 0
1 2 3
0 0 0
0 1 0
0 0 0
];
m(all(m==0,2),:)=[]
%{
% m =
1 0 0
1 2 3
0 1 0
%}
us
%generate random matrix
a=rand(4)
% generate row with zeros
a(3,:)=0
% select nonzero rows
b=a(sum(a')~=0;:)
well...
even after correcting the syntax error...
a=[
1 -1 % <- sum := 0
0 0
2 2
];
b=a(sum(a')~=0,:) % <- chage ; to ,
% b = 2 2
us
aargnnnn! you're right! i'm not...
the only excuse: my example is much more probable than yours :-)
Try searching in google for
matlab how can i remove rows that contain only zeros
you can do it in 2 simple steps:
1. take the original "large matrix (120000*128)", let's call it A, and project onto a one single column, with
B=sum(A,2);
The vector B will have 0s exactly at the locations corresponding to the zero rows of A.
So now:
2. a=find(B>0);
C=A(a,:)
will get rid of the zero rows in A
Counterexample:
A = [1 2 3 4;5 6 7 -18]
You want sum(abs(A), 2) or ~any(A, 2) or all(A==0, 2) instead.
*snip*
--
Steve Lord
sl...@mathworks.com