Why is my plot plotting blank?

Why I keep getting blank for my graph? I figured out that if I change plot(i,P_t(i+1)) to plot(i,P_t(i+1),'.');hold on, it will work. But only I want is a smooth line printed.

Respuestas (1)

Timo Dietz
Timo Dietz el 2 de Feb. de 2021

1 voto

Each loop you are plotting one point, only. So you either have to "hold on" the figure to prevent erasing all data before the next point to plot (this would give you some kind of scatter plot) or you have to plot the array at the end of the function.
So to get a line the last row in the function should look like
plot([1:Year+1], P_t)
You got the point?

3 comentarios

Jan
Jan el 2 de Feb. de 2021
Hint: 1:Year+1 is a vector already. There is no reason to include it in the Matlab operator for concatenation [ ] .
Shuqing Qi
Shuqing Qi el 2 de Feb. de 2021
Thank you so much! I got it!
Timo Dietz
Timo Dietz el 3 de Feb. de 2021
Glad that I could help you. Please accept the answer to close the topic.

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 2 de Feb. de 2021

Comentada:

el 3 de Feb. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by