Index 1 Variable by another

10 ビュー (過去 30 日間)
Hillaryfor2016
Hillaryfor2016 2015 年 4 月 12 日
コメント済み: Star Strider 2015 年 4 月 12 日
Hi there!
I have 2 variables
if true
A = 1
2
NaN
4
end
B= 20
2
5
4
end
I want to remove the '5' from variable B by replacing it with a NaN (i.e. any NaN's in variable A result in a NaN in variable B
I understand this is a simple problem. I have researched but its been a long day Please help x

採用された回答

Star Strider
Star Strider 2015 年 4 月 12 日
Use ‘logical indexing’:
B(isnan(A)) = NaN
produces:
B =
20
2
NaN
4
  2 件のコメント
Hillaryfor2016
Hillaryfor2016 2015 年 4 月 12 日
Worked beautifully, thanks for the help!! x
Star Strider
Star Strider 2015 年 4 月 12 日
My pleasure!

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

その他の回答 (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