Using logical index matrix to create another matrix with values
92 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Birsen Ayaz-Maierhafer
le 3 Août 2022
Commenté : Birsen Ayaz-Maierhafer
le 3 Août 2022
Hi All,
I have a matrix (E) with 180 x45 with values. I would like to create another matrix where the values are >1E9. First I found the indexes (idx) of the values that are >1E9 in matrix E. Now I would like to use that matrix index (idx) to create the another matrix (E2) that have the values that are >1E9. But it created just one column data insted not a matrix. How can I solve this?
Thank you
idx=E>1E9;
E2=E(idx);
Birsen
Réponse acceptée
Steven Lord
le 3 Août 2022
What do you want the elements that did not satisfy the condition in your original matrix to be in the new matrix? You can't have a "Swiss cheese" matrix (one with holes in it.)
Here's one example that fills in where those holes would have been with NaN values.
A = magic(4)
ind = A > 8
B = NaN(4)
B(ind) = A(ind)
Note that if you'd tried to use ind to extract just those elements of A, you are correct that you'd receive a vector. Remember, no holes allowed.
C = A(ind)
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!