Selecting an element from each column of a matrix using another matrix
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(1 个)
Azzi Abdelmalek
2016-2-4
%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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!