How can I remove all rows from a matrix which contain NaN values?
13 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2024-11-14,0:00
评论: Walter Roberson
2024-11-14,6:01
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];
In matrix A defined above, I would like to remove row 2 ([4, NaN, 6]).
采纳的回答
MathWorks Support Team
2024-11-14,0:00
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), :);
1 个评论
Walter Roberson
2024-11-14,6:01
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!