assimble small victors into bigger one using for loop

1 回表示 (過去 30 日間)
abdelrahman alhammadi
abdelrahman alhammadi 2018 年 10 月 12 日
回答済み: Image Analyst 2018 年 10 月 12 日
what if I have vector a1= [1; -1] and a2= [ 1 ;-1 ] and so on ... the big matrix should be like F= [ 1; 0; 1] if the size was(2) how can I do that in a for loop ?
  5 件のコメント
Stephen23
Stephen23 2018 年 10 月 12 日
編集済み: Stephen23 2018 年 10 月 12 日
"what if I have vector a1 ... and a2 ... and so on ... "
then your code should be redesigned:
abdelrahman alhammadi
abdelrahman alhammadi 2018 年 10 月 12 日
yeas if I have a vectors of the same length and I want to assemble them in bigger one

サインインしてコメントする。

回答 (2 件)

Bruno Luong
Bruno Luong 2018 年 10 月 12 日
a1= [1; -1];
a2= [1 ;-1];
a = {a1 a2};
F = zeros(length(a)+1,1);
for i=1:2
F(i+[0,1]) = F(i+[0,1]) + a{i};
end

Image Analyst
Image Analyst 2018 年 10 月 12 日
Lacking any specific and complete rules other than giving a1, a2, to use a for loop, and to give the desired F, this works:
a1 = [1; -1]
a2 = [1 ; -1]
for k = 1 : 3
F(k) = 2 - k;
end

カテゴリ

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

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by