フィルターのクリア

Remove or set a row to 0 when containing NaNs

1 回表示 (過去 30 日間)
Ramiro Rea
Ramiro Rea 2017 年 7 月 11 日
コメント済み: Ramiro Rea 2017 年 7 月 11 日
Hi everyone,
I have an array like this:
tnCT =
3.0070 NaN
18.0067 3.4871
34.0071 4.6240
48.0062 4.9370
138.0044 5.9247
153.0041 6.6163
I want to set to 0 the row that has NaN on it. I have tried the following:
for i = 1:length(tnCT)
if isnan(tnCT(i,:))
tnCT(i,:) = 0;
end
end
So I will end with:
tnCT =
0 0
18.0067 3.4871
34.0071 4.6240
48.0062 4.9370
138.0044 5.9247
153.0041 6.6163
Can you please tell me what is wrong with my approach, since it doesn't work? Removing the values also would do the trick (since in the next step I create a nonzeros matrix)

採用された回答

Walter Roberson
Walter Roberson 2017 年 7 月 11 日
mask = any( isnan(tnCT), 2 ); %find rows with nan
tnCT(mask,:) = []; %delete them
  1 件のコメント
Ramiro Rea
Ramiro Rea 2017 年 7 月 11 日
This did the job, thank you very much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by