How do I store each iteration of my for loop in a vector?
조회 수: 16 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!