I'm trying to check for a NaN value in an array in if condition expression but the control is not entering inside if condition.

1 回表示 (過去 30 日間)
For example :
A = [1 2 3 NaN 3 5]; if isnan(A) ~= 0 %... end

採用された回答

KSSV
KSSV 2017 年 10 月 12 日
A = [1 2 3 NaN 3 5];
idx = isnan(A) ; % all NaN indices at once
for i = 1:length(A)
if isnan(A(i))
fprintf('%d index value is NaN\n',i)
end
end
  2 件のコメント
Bhargav Boddupalli
Bhargav Boddupalli 2017 年 10 月 12 日
Thank you. I was wondering if there is a way skipping use of 'for loop' to read each element.
KSSV
KSSV 2017 年 10 月 12 日
idx = isnan(A) ; % all NaN indices at once
A(~isnan(A))

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by