我有一個大小為:[70 5 3 2 10 9 5 3 21] 的 Matlab 矩陣 M;我有一個帶有我想讀取該矩陣坐標的向量: [5, 1, 1, 2, 3, 4, 1, 2, 1];
我想要得到的 MWE 示例:
M = rand(70 5 3 2 10 9 5 3 21);
coordinates = [5, 1, 1, 2, 3, 4, 1, 2, 1];
% Output desired:
M(5, 1, 1, 2, 3, 4, 1, 2, 1)
%Current attempt:
M(coordinates)
顯然M(coordinates) <> M(5, 1, 1, 2, 3, 4, 1, 2, 1)。有沒有辦法做到這一點?
uj5u.com熱心網友回復:
這有點尷尬,但您可以將陣列轉換為元胞陣列,然后轉換為逗號分隔的串列:
M = rand(70, 5, 3, 2, 10, 9, 5, 3, 21);
coordinates = [5, 1, 1, 2, 3, 4, 1, 2, 1];
coords_cell = num2cell(coordinates);
result = M(coords_cell{:});
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/456631.html
標籤:matlab
