依据二维矩阵中的索引,获取三维数组中的第三维数据。
Show older comments
求助一下,目前我有一个三维数组a=[10,10,5];同时有一个二维矩阵index,大小为(3,2),其中第一列为三维数组的第一维索引,第二列为三维数组的第二维索引,如何取出在这三个索引位置a的第三维数据,也就是得到大小为(3,5)的矩阵。
a = rand(10, 10, 5);
index = [1,2; 2,4; 5,7];
result = zeros(3,5);
for k = 1:size(index, 1)
result(k.:) = a(index(k,1), index(k,2), :);
end
我目前只能想到使用一个循环来获得,但是需要追求效率,想请问各位有更高效的方法嘛
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!