Select values in one column based on entries in another column
40 views (last 30 days)
I looking for a way to read values in one column based on the entries in qnother column,
For example in the attached array A, the first entry in the first column is -3.14, here I would like to read all the correponding entries in the third column whichever got -3.14 in the first column..
More Answers (1)
Arthur Reis on 21 Feb 2022
Edited: Arthur Reis on 21 Feb 2022
You can use a logical mask. For example (using two vectors, but it is easily adaptable for your case with arrays with many columns):
A = [1; 2; 3; -3.14; 4; -3.14];
>> A_mask = (A==-3.14) % also works with <, >, >=, <=.....
6×1 logical array
>> B = ['a'; 'b'; 'c'; 'd'; 'e'; 'f']
6×1 char array
>> B(A_mask) %passing a logical array as indexes will return every 'true' element
2×1 char array