是否可以使用矩阵条目作为其他矩阵的索引?例如:
A=[1 2 ; 4 5 ; 6 7 ];我想使用A到达其他矩阵的条目,而不是使用循环。
Othermat(1,2), Othermat(4,5) %...如果是,我该怎么做?!
发布于 2013-11-27 16:15:47
当然,使用sub2ind
A = [1 2; 4 5; 6 7];
ind = sub2ind(size(Othermat),A(:,1),A(:,2));
values = Othermat(ind);发布于 2013-11-27 22:04:11
建议的sub2ind是生成索引的一种自然方式。
当然,直接找到线性索引也不是很难:
A = [1 2; 4 5; 6 7];
Othermat = magic(7);
Othermat(A(:,1)+(A(:,2)-1)*size(Othermat,1))https://stackoverflow.com/questions/20237038
复制相似问题