Extracting row elements from different columns using an index
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have two 18x4 matrices of various integer sized data (say A and B). I am trying to collapse the second matrix (B) into an 18x1 array using an index created by the first matrix (A), the index which is that of the largest integers in each row of the first matrix (A).
I've attempted to do this by using an [~,idx] = max(A,[],2), but am having some trouble extracting the data out of B using the index. Is there a way to do that, or an even better approach?
I am attempting to use the logic I find here to apply to two 5D matrices collapsed along the 5th dimension by minimum value.
Thank you.
0 Kommentare
Akzeptierte Antwort
Fangjun Jiang
am 13 Okt. 2011
A=rand(18,4);
B=rand(18,4);
[Ma,indA]=max(A,[],2);
indB=sub2ind(size(A),(1:size(A,1))',indA);
Sb=B(indB)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!