フィルターのクリア

Replacing a value with nan

2 ビュー (過去 30 日間)
Elaheh
Elaheh 2018 年 4 月 18 日
回答済み: Dennis 2018 年 4 月 18 日
Hello all. I want to replace a value that I have in accuracyC with nan if its counterpart value is nan in RTc. RTc and accuracyC are two matrices. I have written this loop but it does not work. I appreciate your help.
h=0;
for i=1:size(accuracyC,1)
for j=1:size(accuracyC,2)
if RTc(i,j)==nan
accuracyC(i,j)=NaN;
h=h+1;
end
end
end

採用された回答

Star Strider
Star Strider 2018 年 4 月 18 日

Try this:

RTc = [1 2 3 NaN; 4 5 6 7; NaN 8 9 10]                      % Create Matrix
AccuracyC = randi(9, size(RTc))                             % Create Matrix
AccuracyC(isnan(RTc)) = NaN                                 % Desired Result
RTc =
       1     2     3   NaN
       4     5     6     7
     NaN     8     9    10
AccuracyC =
       7     1     6     6
       8     3     9     3
       1     8     2     1
AccuracyC =
       7     1     6   NaN
       8     3     9     3
     NaN     8     2     1

その他の回答 (1 件)

Dennis
Dennis 2018 年 4 月 18 日

I read about this lately, NaN never equals NaN (some IEEE stuff).

But you can use isnan instead.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by