Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个A包含m行的矩阵,我想将每行的特定元素设置为 1。列索引因行而异,由列向量a(带m值)指定。也就是说,我想要A_{i,a_i} = 1. 在 Matlab 中是否有一种快速的方法(没有 for 循环)?
A
m
a
A_{i,a_i} = 1
我使用以下sub2ind函数解决了它:
sub2ind
A(sub2ind(size(A), 1:numel(a), a')) = 1