Find column where one value is NaN

34 ビュー (過去 30 日間)
Martin Holding
Martin Holding 2019 年 11 月 19 日
回答済み: Stephan 2019 年 11 月 19 日
Hi,
I have a long matrix containing 2 rows and many thousands of columns. The values are either 0.5 or NaN. I want to be able to locate any columns where only the second row is equal to NaN and the first row is equal to 0.5. For example the matrix:
a = [0.5, NaN, 0.5, 0.5, 0.5;
0.5, NaN, 0.5, NaN, NaN]
should return the indices [4, 5].
Is this possible using some variation of the find function? I can use find to locate the columns where both rows are equal to either 0.5 or NaN but I can't figure out how to do it where one row is 0.5 and one row isn't. If it isn't possible using find what is the most succint way of achieving this?
Thanks,
Martin

採用された回答

Stephan
Stephan 2019 年 11 月 19 日
res = find(~isnan(a(1,:)) & isnan(a(2,:))==1)

その他の回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 11 月 19 日
編集済み: KALYAN ACHARJYA 2019 年 11 月 19 日
"Find column where one value is NaN"
a=[0.5, NaN, 0.5, 0.5, 0.5;
0.5, NaN, 0.5, NaN, NaN];
[r,c]=find(isnan(a));
col_data=setdiff(c,r)

カテゴリ

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

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by