Using logical index matrix to create another matrix with values
8 views (last 30 days)
Birsen Ayaz-Maierhafer on 3 Aug 2022
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?
Steven Lord on 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)