Find first row with certain value in x2 array
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gevin Schaeffer
am 7 Jun. 2021
Kommentiert: Gevin Schaeffer
am 8 Jun. 2021
I have an 300x2 array in which I need to find a certain numbert in colum 1, e.g. 10. Once the number is found I need to extract the corresponding value in colum 2.
Akzeptierte Antwort
Chunru
am 8 Jun. 2021
idx = A(:, 1) == 10; % find the index that 1st column = 10
b = A(idx, 2); % extract the corresponding data in 2nd column
Or in one line
b = A(A(:,1)==10, 2);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing 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!