How can I remove all rows from a matrix which contain NaN values?
20 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2024 年 11 月 14 日
編集済み: MathWorks Support Team
2025 年 1 月 29 日 13:43
How can I remove all rows from a matrix which contain NaN values?
For example:
>> A = [1, 2, 3; 4, NaN, 6; 7, 8, 9]
A =
1 2 3
4 NaN 6
7 8 9
In matrix A defined above, I would like to remove the second row, [4, NaN, 6].
採用された回答
MathWorks Support Team
2025 年 1 月 29 日 0:00
編集済み: MathWorks Support Team
2025 年 1 月 29 日 13:43
Use the following code to remove all rows which contain NaN values from a matrix A:
>> A = [1, 2, 3; 4, NaN, 6; 7, 8, 9];
>> A = A(~any(isnan(A), 2), :)
A =
1 2 3
7 8 9
Alternatively, make use of the function "rmmissing" to remove any row that contains missing data, as shown below.
>> A = [1, 2, 3; 4, NaN, 6; 7, 8, 9];
>> A = rmmissing(A)
A =
1 2 3
7 8 9
1 件のコメント
Walter Roberson
2024 年 11 月 14 日
A = [1, 2, 3; 4, NaN, 6; 7, 8, 9];
A = rmmissing(A)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Numeric Types についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!