Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Star Strider
Star Strider el 10 de Dic. de 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));
.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by