How do I plot a line rather than seperate points?

1 visualización (últimos 30 días)
Rowan Miller
Rowan Miller el 5 de Dic. de 2017
Respondida: John D'Errico el 5 de Dic. de 2017
t = -2;
yo = 5;
w = 5;
k = 0.1;
for t = -2:20
if t < 0
y = -yo;
elseif t < 10
y = -yo*(cos(w*t));
else
y = -yo*(cos(w*t))*exp(-k*(t-10));
end
plot(t,y,'.'); hold on
end
hold off
This is the code. I've looked everywhere and I just cannot figure out how to plot the oscillation curve I need from the given data in the code. Any help is appreciated. Thank you.

Respuesta aceptada

John D'Errico
John D'Errico el 5 de Dic. de 2017
Don't plot each point, ONE at a time. You cannot easily connect a new point to the last. (Well, you could do it, but it would be insanely silly to do so.)
Create the result as a vector, then call plot ONCE.
Learn how to use MATLAB. MATLAB is all about vectors and arrays.

Más respuestas (0)

Categorías

Más información sobre Scatter Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by