Clear Filters
Clear Filters

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

3 views (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 10 Dec 2020
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));
.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!