Filtering out indices of vector A based on restrictions applied to vector B
60 views (last 30 days)
Suppose i have to vectors A and B or size [1,20]. After filtering out cases with NaNs on each I will get 10 good pairs of data from A and B. Then I have to apply a restriction to B, such as finding data points which are lower than a particular number. I was able to do that, but now i am stuck with how to get corresponding value from A, for the values of B which satisfied the restriction.
dpb on 17 Jun 2017
Edited: dpb on 18 Jun 2017
ix=B<thresh; % logical addressing vector of the condition
C=A(ix); % use it to access A
you can, of course, dispense with the temporary unless have need for it for additional addressing operations as
The condition can be anything that reduces to a logical array of the same length as the array or actual indices from lookup functions such as find.
The from root arrays solution w/o parsing down the original arrays that the above assumes start with--
ix=all(isfinite([A B]),2); % the rows with neither NaN
A(ix&B<=THRSHOLD); % all finite and B<=threshold from originals
It's possible to do away with the temporary ix as well...