grabbing specific rows from matrix
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
giuseppe insignito
am 9 Sep. 2022
Bearbeitet: David Hill
am 9 Sep. 2022
I have the following 25 x 3 matrix (let's call first column X, second Y, third INDEX)
xy_index =
1 1 1
2 1 2
3 1 3
4 1 4
5 1 5
1 2 6
2 2 7
3 2 8
4 2 9
5 2 10
1 3 11
2 3 12
3 3 13
4 3 14
5 3 15
1 4 16
2 4 17
3 4 18
4 4 19
5 4 20
1 5 21
2 5 22
3 5 23
4 5 24
5 5 25
I want to extract rows (and so X,Y and INDEX) corresponding to INDEX [1 5 13 21 25] (as an array). Result shoud be
extracted_xy_index =
1 1 1
5 1 5
3 3 13
1 5 21
5 5 25
Thanks!
0 Kommentare
Akzeptierte Antwort
Fangjun Jiang
am 9 Sep. 2022
Bearbeitet: Fangjun Jiang
am 9 Sep. 2022
RowSelection=[1 5 13 21 25];
xy_index(RowSelection ,:)
Weitere Antworten (1)
David Hill
am 9 Sep. 2022
Bearbeitet: David Hill
am 9 Sep. 2022
idx=ismember(xy_index(:,3),index);
extracted_xy_index=xy_index(idx,:);
0 Kommentare
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!