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

8 次查看(过去 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