using nested loop function to create a matrix

3 ビュー (過去 30 日間)
Aaron Varma
Aaron Varma 2020 年 6 月 18 日
コメント済み: Aaron Varma 2020 年 6 月 18 日
Hi everyone i'm stuck on something that's probably quite simple, wondering if someone can lend a hand
using:
for slowIndex = 1:s
for fastindex = 1:s
H(slowIndex,fastIndex) = movavg(eurUSDClose,'exponential',slowIndex);
end
end
I took this from the MATLAB help section and am trying to amend it for what i need, can some one tell me what I must add to get the loop to run through the fastIndex as well? The end resulty should be a matrix with s number of rows and s number of colums. Eventually fastIndex and slowIndex will contain different values i'm just tryng to get my head around the basics as this stage.

採用された回答

David Hill
David Hill 2020 年 6 月 18 日
You can watch the 1's being filled in:
s=10;
H=zeros(s);
J=zeros(s);
for k=1:s
for m=1:s
H(k,m)=1;%simple double for-loop, first row is filled in, then second row, ...
J(m,k)=1;%first column is filled in, then second column, ...
end
end
  1 件のコメント
Aaron Varma
Aaron Varma 2020 年 6 月 18 日
Thanks for the answer David appreciate it. That did work, probelm is i'm asking the wrong the question, need to have a little rethink about what it is i actully need to get out of this.
Very new with MATLAB!!
Thanks

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

その他の回答 (0 件)

カテゴリ

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