依据二维矩阵中的索引,获取三维数组中的第三维数据。
Mostra commenti meno recenti
求助一下,目前我有一个三维数组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
我目前只能想到使用一个循环来获得,但是需要追求效率,想请问各位有更高效的方法嘛
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!