find columns adjacent to logical values

1 Ansicht (letzte 30 Tage)
Kendal
Kendal am 9 Nov. 2022
Bearbeitet: Davide Masiello am 9 Nov. 2022
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!

Akzeptierte Antwort

Davide Masiello
Davide Masiello am 9 Nov. 2022
Bearbeitet: Davide Masiello am 9 Nov. 2022
Reductive example.
Assume this is your matrix
A = rand(10,5)
A = 10×5
0.4819 0.2483 0.5543 0.6585 0.4306 0.5205 0.2473 0.1807 0.8899 0.0689 0.6271 0.8645 0.1726 0.3300 0.0021 0.9030 0.4220 0.6756 0.5934 0.3190 0.6643 0.9282 0.2688 0.0365 0.7305 0.7736 0.5321 0.4766 0.1201 0.4216 0.7856 0.4446 0.1461 0.6768 0.7840 0.2485 0.5993 0.0980 0.1769 0.1161 0.2677 0.7513 0.0470 0.2053 0.0956 0.4876 0.9653 0.8477 0.7623 0.1845
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
b = 6×1
0.1807 0.1726 0.6756 0.2688 0.4766 0.1461
c = A(A(:,1) > 0.5,5) % extracts values from 5th colum that correspond to values > 0.5 in the first column
c = 6×1
0.0689 0.0021 0.3190 0.7305 0.4216 0.7840
You can easily apply these indexing criteria to your case.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by