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

3 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Jonas
Jonas am 16 Jul. 2021
Bearbeitet: Jonas am 16 Jul. 2021
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)

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 16 Jul. 2021
valgood = imag(YourMatrix)==0;
rowmask = all(valgood,2);
colmask = all(valgood,1);
newMatrix = YourMatrix(rowmask, colmask);

Kategorien

Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by