end
I need to vectorize this for loop, but i am having trouble. so far I have this. I do not understand what I am doing wrong. I understand the concept of what I am trying to do, but having trouble applying it.
ni = 8;
k=2:9;
j=[];
y=[];
y(1) = 12 + 6*cos(0);
j =cumsum((k-1)*((20)/ni));
y(k) = 12 + 6*cos(2*pi.*j./20);
any help would be greatly appreciated.

2 件のコメント

Matt J
Matt J 2014 年 11 月 28 日
編集済み: Matt J 2014 年 11 月 28 日
any help would be greatly appreciated.
Your help would be appreciated, too. Please highlight your code and use the
button to put it in a more readable font, distinct from your text.
Brian
Brian 2014 年 11 月 28 日
thank you. First time using the forums.

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

 採用された回答

Guillaume
Guillaume 2014 年 11 月 28 日
編集済み: Guillaume 2014 年 11 月 28 日

0 投票

You're overcomplicating. I'm not sure what you're trying to do with cumsum
tstart = 0;
tend = 20;
ni = 8;
t = linspace(tstart, tend, ni+1);
y = 12 + 6*cos(2*pi*t/(tend-tstart)); %same expression as original with the index

1 件のコメント

Brian
Brian 2014 年 11 月 28 日
ahh thank you. I was actually misunderstanding what the variable "t"'s function was in the program. This clears it up for me. Thank you again.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2014 年 11 月 28 日

編集済み:

2014 年 11 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by