How do I store each iteration of my for loop in a vector?

15 ビュー (過去 30 日間)
Julia Hariharan
Julia Hariharan 2020 年 12 月 10 日
コメント済み: Star Strider 2020 年 12 月 10 日
Hello, I have a very basic problem that I'm sure I've solved before but for some reason am having a lot of trouble with it. I am trying to get 24 results for a function (called x in my file) with the sample variable going from 0 to 23 and I want to store my data for x in a vector so I can later put it in a table. This should be an easy problem to fix but for whatever reason I have not been able to do so. I've put my code below (it is only a couple lines) and if anyone could help me I would really appreciate it - thanks!
%60 Hz signal
%N=24 and k=N-1
for k=0:1:23
x=100*sqrt(2)*cos(2*pi*60*(k/1440) +(pi/4))
end

採用された回答

Star Strider
Star Strider 2020 年 12 月 10 日
Subscript ‘x’:
for k=0:1:23
x(k+1) = 100*sqrt(2)*cos(2*pi*60*(k/1440) +(pi/4));
end
however the loop is not necessary:
k=0:1:23;
x = 100*sqrt(2)*cos(2*pi*60*(k/1440) +(pi/4));
.
  2 件のコメント
Julia Hariharan
Julia Hariharan 2020 年 12 月 10 日
Thank you so much! This worked!
Star Strider
Star Strider 2020 年 12 月 10 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by