matlab - 给定沿每个轴的索引向量,获取矩阵值

标签 matlab

我有一个Matlab矩阵M,大小为:[70 5 3 2 10 9 5 3 21]; 我有一个带有我想读取该矩阵坐标的向量: [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) 。有办法做到这一点吗?

最佳答案

这有点尴尬,但您可以将数组转换为元胞数组,然后转换为逗号分隔的列表:

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{:});

关于matlab - 给定沿每个轴的索引向量,获取矩阵值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71713041/

相关文章:

python - 将结构体元胞数组从 Python 传递到 MATLAB

matlab - Mex 函数在重新编译后未更新

matlab - Latex变量自动化: writing variables for Latex directly from Stata and MATLAB

matlab - 等值线图水平值的总和

matlab - 如何求不均匀波形的包络线

python - scipy 多项式 pmf 返回 nan

image - 如何将 Gabor 小波应用于图像?

matlab - Matlab 中的 3D RGB 图

matlab - 在 MATLAB 中将音频和视频合并为视频文件

matlab - 使用氡气和伊拉东气时,重建图像中出现莫尔图案