erase a column that contains at least one zero
Show older comments
Hi all,
I have
[N,T,R]=xlsread(name);
R(:,2) contains NaNs and string variables. But sometimes R(:,2) contains and zeros. I want to check if R(:,2) contains at least one zero . If yes, then I want to erase the first column of N, that is N(:,1).
So I try this
R2 = R(:,2);
R22 = R2(cellfun(@(x)isnumeric(x),R2));
if any(cell2mat(R22)==0)
N(:,1) = [];
end
Is there any alternative which is more compact ?
4 Comments
Sabbas
on 5 Jul 2012
Image Analyst
on 6 Jul 2012
Why does it need to be more compact? I suppose you could do all that on two or three lines if you really wanted to.
Sabbas
on 6 Jul 2012
Geoff
on 6 Jul 2012
Small syntax simplification....
cellfun(@(x)isnumeric(x),R2)
Can just be:
cellfun(@isnumeric,R2)
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!