Extract indices from other matrix corresponding to the minimum
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I currently have a matrix in which I want to determine the column which corresponds to the minimum of each row, which I can do the following way:
Mat = rand(30, 2) ;
[~, min_idx] = min(Mat, [], 2, 'linear') ;
[~, col] = ind2sub(size(Mat), min_idx) ;
Following that, I would like to use col, to extract the corresponding 3rd dimension in another matrix X:
X = rand(30, 3, 2) ;
Xmin = X(:,:,col) ;
For Xmin I would expect to get a 2D matrix, where each row corresponds to the index col in the 3rd dimention extracted from X, however that is not the case for some reason. Do you know how I could accomplish the above?
Thanks for your help in advance.
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
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!