How to use the index ? how to drop elements from a matrix ?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Wayne King
2013-11-30
编辑:Wayne King
2013-11-30
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 个评论
更多回答(2 个)
Azzi Abdelmalek
2013-11-30
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 个评论
Andrei Bobrov
2013-11-30
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!