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

조회 수: 16 (최근 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by