# Problems with double looping

2 ビュー (過去 30 日間)
Armando MAROZZI 2020 年 4 月 8 日

I am trying to implement this double loop. There is lot of material online on double looping in matlab but I don't manage to make it work.
This is my code:
debt = nan(49,1)
for j = -(6:12)
for i = 2:8
debt(j, i) = ((1 + 0.93) - (1 + j)) + 134.77 + (i - 3.3)
end
end
I would like to be able to save debt as a 49x1 vector.
What's wrong with my loop?
Thanks

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

### 採用された回答

Andrei Bobrov 2020 年 4 月 8 日

Just:
ii = 2:8;
jj = -(6:12);
debt = 132.4 - jj(:) + ii(:)';
debt = debt(:);
or with for-loop:
ii = 2:8;
jj = -(6:12);
debt = nan(7);
for j = 1:7
for i = 1:7
debt(j, i) = 132.4 - jj(j) + ii(i);
end
end
##### 4 件のコメント表示非表示 3 件の古いコメント
Armando MAROZZI 2020 年 4 月 8 日
great! Thanks a lot!

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

### カテゴリ

Find more on Loops and Conditional Statements in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by