Finding the position of a cell within a Matrix
5 ビュー (過去 30 日間)
古いコメントを表示
Hello Fellow Developer,
i have been given a 100x13 Matrix with Integers in it. But in one cell there is NaN written in it.
I know that the cell with NaN is in column two, so I tried the following code: But my Variable k never changes to one.
for i=1:100
if Matrix(i, 2) == 'NaN'
k = 1
end
end
0 件のコメント
採用された回答
その他の回答 (2 件)
Ameer Hamza
2020 年 6 月 5 日
編集済み: Ameer Hamza
2020 年 6 月 5 日
isnan() is used to detect nan. You can write your code without for-loop
k = any(isnan(Matrix(:,2)))
4 件のコメント
Ameer Hamza
2020 年 6 月 5 日
If you want to find the row, then something like this will work
idx = find(isnan(Matrix(:,2)))
Jake Bowd
2020 年 6 月 5 日
Hi,
Could you use the following?
m = ; % whatever the matrix is called.
[row, column] = find(m == NaN)
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!