substituting value in matrix does not work for some reason
3 次查看(过去 30 天)
显示 更早的评论
A = [6 9 NaN NaN 8 NaN]; B = [2 5 342 232 1 116];
sizeA = size(A);
for m = [1:1:size(2)];
if A(1,m) == NaN;
B(1,m) = NaN;
end;
end;
I was hoping B would become [2 5 NaN NaN 8 NaN], but it did not change. I would appreciate any help
0 个评论
采纳的回答
Kelly Kearney
2014-11-18
编辑:Kelly Kearney
2014-11-18
You can't use == with NaNs:
>> NaN == NaN
ans =
0
Use isnan instead:
B(isnan(A)) = NaN;
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!