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

3 ビュー (過去 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?
  1 件のコメント
Michael
Michael 2021 年 7 月 16 日
編集済み: Walter Roberson 2021 年 7 月 16 日
You should be able to loop through the columns or rows of the array and check them with isreal:

サインインしてコメントする。

採用された回答

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 Center および File ExchangeOperators and Elementary Operations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by