How to use the index ? how to drop elements from a matrix ?
1 view (last 30 days)
Show older comments
I have a matrix b(j,w) = b(3,4)
b= [
0.0913 NaN NaN NaN
0.0913 NaN NaN NaN
0.0913 NaN NaN NaN ]
and g(j,w)=g(3,4)
60 60 60 60
70 70 70 70
75 75 75 75
I want to drop the elements in g that have a correspondent NAN value in b.
0 Comments
Accepted Answer
Wayne King
on 30 Nov 2013
Edited: Wayne King
on 30 Nov 2013
One of many ways:
b= [
0.0913 NaN NaN NaN
0.0913 NaN NaN NaN
0.0913 NaN NaN NaN ];
g = [60 60 60 60
70 70 70 70
75 75 75 75];
idx = ~isnan(b);
g = g(idx>0);
0 Comments
More Answers (2)
Azzi Abdelmalek
on 30 Nov 2013
b= [ 0.0913 NaN NaN NaN
0.0913 NaN NaN NaN
0.0913 NaN NaN NaN ]
c=[ 60 60 60 60
70 70 70 70
75 75 75 75]
idx=any(~isnan(b),1)
c=c(:,idx)
0 Comments
Andrei Bobrov
on 30 Nov 2013
b = [0.0913 NaN NaN NaN
0.0913 NaN NaN NaN
0.0913 NaN NaN NaN];
g = [60 60 60 60
70 70 70 70
75 75 75 75];
>> g(~isnan(b))
ans =
60
70
75
0 Comments
See Also
Categories
Find more on NaNs 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!