Specify row and column independently to update matrix?

1 回表示 (過去 30 日間)
Andrew Landau
Andrew Landau 2018 年 3 月 4 日
コメント済み: Andrew Landau 2018 年 3 月 4 日
Lets say I have a matrix: X = zeros(3);
and want to add a vector: x = [1 2 3]; to the matrix, but add it such that each number is added to a different column in each row defined by y = [1 2 3].
I could write a for loop,
for i = 1:length(x)
X(i,y(i)) = x(i);
end
but it should be possible to do this in a single line....
any suggestions? thanks

採用された回答

Jos (10584)
Jos (10584) 2018 年 3 月 4 日

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by