Selecting an element from each column of a matrix using another matrix
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Charles Brown-King
am 4 Feb. 2016
Beantwortet: Azzi Abdelmalek
am 4 Feb. 2016
I have a 130x87 matrix (A) and I need to select an element from each column based on the numbers in a 1x87 matrix (B). So if the first number in matrix B is 12, I need the 12th number in the first column of matrix A.
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Azzi Abdelmalek
am 4 Feb. 2016
%Example
A= randi(10,5,6)
B =randi(5,1,6)
%---------------------
[n,m]=size(A);
idx=B+(0:n:n*(m-1))
out=A(idx)
0 Kommentare
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!