How can I cancel ("NaN" value) elements of a matrix based on another matrix's "NaN" values?

1 回表示 (過去 30 日間)
André Gadêlha
André Gadêlha 2017 年 9 月 25 日
コメント済み: Stephen23 2017 年 9 月 25 日
Hi everyone,
Let's suppose I have a matrix A: A = 1 2 3; 4 5 6; 7 8 9
and a matrix B: B= 1 NaN 3; NaN 5 6; 7 NaN NaN
I want to cancel the same elements that are canceled in matrix B. It would be:
A2= 1 NaN 3; NaN 5 6; 7 NaN NaN
How can I do that?

回答 (2 件)

OCDER
OCDER 2017 年 9 月 25 日
Use isnan to find where NaN values are. Then replace elements in A with NaN to get A2.
A2 = A;
A2(isnan(B)) = NaN;
A2 =
1 NaN 3
NaN 5 6
7 NaN NaN

Andrei Bobrov
Andrei Bobrov 2017 年 9 月 25 日

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by