Delete/remove entire rows and columns containing an element that satisfies a condition (e.g. when the element is an imaginary number)
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Saeid
le 16 Juil 2021
Réponse apportée : Walter Roberson
le 16 Juil 2021
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 commentaire
Michael
le 16 Juil 2021
Modifié(e) : Walter Roberson
le 16 Juil 2021
You should be able to loop through the columns or rows of the array and check them with isreal:
Réponse acceptée
Jonas
le 16 Juil 2021
Modifié(e) : Jonas
le 16 Juil 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)
0 commentaires
Plus de réponses (1)
Walter Roberson
le 16 Juil 2021
valgood = imag(YourMatrix)==0;
rowmask = all(valgood,2);
colmask = all(valgood,1);
newMatrix = YourMatrix(rowmask, colmask);
0 commentaires
Voir également
Catégories
En savoir plus sur Operators and Elementary Operations dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!