how to exclude a row from a matrix

조회 수: 17 (최근 30일)
D.J
D.J 2018년 10월 3일
댓글: D.J 2018년 10월 3일
Hi all, I need to extract all data from a matrix except for one row (the 3rd from last).
Say for example I have the matrix below and I want to exclude this row: [NAN,7,7] Any idea how to do that? Many thanks
T=[1,2,3;4,5,6;7,8,9;1,2,3;4,5,6;7,8,9; NAN,7,7;4,5,6;7,8,9]
  댓글 수: 1
Bob Thompson
Bob Thompson 2018년 10월 3일
I would suggest using an isnan check. Not entirely sure how it will treat an entire row, but a place to start.
T=[1,2,3;4,5,6;7,8,9;1,2,3;4,5,6;7,8,9; NAN,7,7;4,5,6;7,8,9];
T = T(~isnan(T),:);
I suspect you will need:
T = T(~isnan(T(:,1)),:);

댓글을 달려면 로그인하십시오.

채택된 답변

the cyclist
the cyclist 2018년 10월 3일
Assuming that what you want is to exclude any row with a NaN in any position, then either
T = T(all(~isnan(T),2),:);
or
T(any(isnan(T),2),:) = [];
will do the job.
  댓글 수: 1
D.J
D.J 2018년 10월 3일
There was a problem with the first option, but the 2nd one worked perfectly well. Thank you very much.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by