Eliminate Nan row in a large matrix

조회 수: 1 (최근 30일)
NAFTALI HERSCOVICI
NAFTALI HERSCOVICI 2024년 9월 17일
편집: Walter Roberson 2024년 9월 17일
Hello,
I have a very large matrix where some elements are Nan.
I would like to delete the rows containing the these elements.
Example
For
A=[1 2 3; 2 4 Nan; 4 5 6; nan 9 0];
Output:
A=[1 2 3];
Any ideas?
Thank you

채택된 답변

Voss
Voss 2024년 9월 17일
A(any(isnan(A),2),:) = [];

추가 답변 (1개)

Manish
Manish 2024년 9월 17일
편집: Manish 2024년 9월 17일
Hi ,
I understand that you want that eliminate NaN rows in the matrix,we can achive this with help of ‘isnan’ function.
Here is the code example:
A = [1 2 3; 2 4 NaN; 4 5 6; NaN 9 0];
% Find rows with any NaN values
rowsWithNaN = any(isnan(A), 2);
% Keep only rows without NaN values
A = A(~rowsWithNaN, :);
% Display the result
disp(A)
1 2 3 4 5 6
Hope it helps!

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by