add to a vector by plus 1 and plus 2

2 ビュー (過去 30 日間)
polo Mahmoud
polo Mahmoud 2019 年 12 月 9 日
回答済み: ME 2019 年 12 月 9 日
hi if you have a vector like this:
X = [1;2;3];
and want to plus number 1 with 1 and number 2 with 2 ect.
can this be done in a loop ?

回答 (1 件)

ME
ME 2019 年 12 月 9 日
I think this should do what you are after
X = [1;2;3];
for i=1:3
X(i) = X(i)+i;
end
Another way would be to do:
X = [1;2;3];
Y=1:3;
X=X+Y';

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by