find columns adjacent to logical values
1 view (last 30 days)
Show older comments
I have a table with 891 rows and 12 colums. I have sorted 1 column logically (0's and 1's) and need to pull out data from 2 other columns adjacent to the 1's.
Any assistance will be greatly appreciated!
0 Comments
Accepted Answer
Davide Masiello
on 9 Nov 2022
Edited: Davide Masiello
on 9 Nov 2022
Reductive example.
Assume this is your matrix
A = rand(10,5)
and let's assume your logical criteria is that you want to extract all the values in column 3 and 5 that correspond to values in column one which are greater than 0.5.
Then you simply do
b = A(A(:,1) > 0.5,3) % extracts values from 3rd colum that correspond to values > 0.5 in the first column
c = A(A(:,1) > 0.5,5) % extracts values from 5th colum that correspond to values > 0.5 in the first column
You can easily apply these indexing criteria to your case.
0 Comments
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!