Reputation: 52850
I need a command to check for zero sparse matrix, isempty(..) does not work. Is there some sparse version of isempty(..)?
>> mlf2=sparse([],[],[],2^31+1,1)
mlf2 =
All zero sparse: 2147483649-by-1
>> isempty(mlf2)
ans =
0 % I waited for 1 here with the zero sparse matrix...
Upvotes: 1
Views: 1178
Reputation: 3551
Try
~nnz(mlf2)
or
isempty(find(mlf2))
Edit:
Mohsen Nosratinia pointed out that isempty(find(mlf2), 1)
is more efficient because it the find
command will either return a matrix of length 1, or an empty matrix
Upvotes: 6