Delete/remove entire rows and columns containing an element that satisfies a condition (e.g. when the element is an imaginary number)

조회 수: 7 (최근 30일)
In an array containing elements that are imaginary numbers, how can I remove the entire row(s) and column(s) containing any of these numbers?

채택된 답변

Jonas
Jonas 2021년 7월 16일
편집: Jonas 2021년 7월 16일
where=yourMatrix==yourCondition;
yourMatrix(any(where,2),:)=[];
yourMatrix(:,any(where,1))=[];
or
[row,col]=find(where);
yourMatrix(row,:)=[];
yourMatrix(:,col)=[];
if your condition being a complex number you can use where=~isreal(yourMatrix)

추가 답변 (1개)

Walter Roberson
Walter Roberson 2021년 7월 16일
valgood = imag(YourMatrix)==0;
rowmask = all(valgood,2);
colmask = all(valgood,1);
newMatrix = YourMatrix(rowmask, colmask);

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by