I have an array of 13x14 double I want to remove some elements that are not in a particular order and the rest of the elements Make NaN.
For example, if
A = [0.2 0.3 0.6 0.4 0.1 0.5 0.2 0.8 0.7 0.1 0.5 0.9 0.2 0.5 0.6 0.7]
I want to remove the index (2,1), (2,3) (3,3) and (4,2) element and want to make the rest in the form of Nain. So the final output should be:
[NaN NaN NaN NAN 0.1 NaN 0.2 NaN NaN NaN 0.5 NaN NaN 0.5 NaN NaN]
I try logical sequencing But it gives me a vector that I do not want because then you can not reshape it and make it a 2-D array. I want a 2-D array thanks.
You can fill a full-size matrix with NAn and then use linear . The values wanted to index indexes to overwrite NANO:
A = [0.2 0.3 0.6 0.4 0.1 0.5 0.2 0.8 0.7 0.1 0.5 0.9 0.2 0.5 0.6 0.7]% (2,1), (2, 3) (3,3) and (4,2)% // reads as ... rows = [2, 2, 3, 4]; Column = [1, 3, 3, 2]; Idx = sub2ind (size (A), rows, columns)% of index / as linear index / out = NaN size (A)); Nyan full of% // matrix (A-shaped A) out (idx) = a (idx); % // Overwrite with values from A in the given index
Comments
Post a Comment