Using logical index matrix to create another matrix with values
91 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Birsen Ayaz-Maierhafer
am 3 Aug. 2022
Kommentiert: Birsen Ayaz-Maierhafer
am 3 Aug. 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
Akzeptierte Antwort
Steven Lord
am 3 Aug. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!