How to plot points on a graph using for loop?

I am working on a project, and I am trying to graph an ascent rate where the y axis is feet and the x axis is minutes. I want it to plot a point every minute, where it increases 2000 feet per minute until the cruising altitude. I have to use a for loop, and so far I have got it to plot the points on the y axis but not the x axis. This is also based off of a GUI, so the numbers below are able to be changed. sa= starting altitude, A1=crusing altitude, ar=ascent rate, FS=font size
sa=0;
elevation=525;
A1=30000;
minutes=135;
x=elevation:2000:A1;
for i=1:length(x)
ar(i)=sa+x(i);
end
FS=12;
%axes(handles.timevsheight);
plot(0,ar,1,ar,'-o r','linewidth',2);
xlabel('Time (Minutes)','Interpreter','latex','FontSize',FS);
ylabel('Height (Feet)','Interpreter','latex','FontSize',FS);
xlim([0 minutes+5])
ylim([0 A1+1000])
title('Time vs Height')

1 comentario

Rik
Rik el 9 de Mayo de 2022
Based on your labels you want to plot the altitude versus time. Have you tried creating vectors with paired data? Because that is what you will need in the end: pairs of altitude and time. I don't fully understand what you're doing in your code to be able to tell you what exactly you should change to get what you need.

Iniciar sesión para comentar.

Respuestas (1)

Mahmoud Ashraf
Mahmoud Ashraf el 5 de Mayo de 2022
Editada: Mahmoud Ashraf el 5 de Mayo de 2022
sa=0;
elevation=525;
A1=30000;
minutes=135;
x=elevation:2000:A1;
for i=1:length(x)
ar(i)=sa+x(i);
end
FS=12;
%axes(handles.timevsheight);
plot(0,ar,'-o r','linewidth',2);
xlabel('Time (Minutes)','Interpreter','latex','FontSize',FS);
ylabel('Height (Feet)','Interpreter','latex','FontSize',FS);
xlim([0 minutes+5])
ylim([0 A1+1000])
title('Time vs Height')

4 comentarios

Mahmoud Ashraf
Mahmoud Ashraf el 5 de Mayo de 2022
i think if you plot x-vector and ar-vector that will produce the graph you want
Mahmoud Ashraf
Mahmoud Ashraf el 5 de Mayo de 2022
Editada: Mahmoud Ashraf el 5 de Mayo de 2022
or use plot(0,ar)
that make all point in y axis only
Hunter Nau
Hunter Nau el 5 de Mayo de 2022
I need the x value to increase by one everytime instead of it being a straight line. (0,525) (1,2525)(2,4525)etc
Mahmoud Ashraf
Mahmoud Ashraf el 5 de Mayo de 2022
use scatter (x,y) instead of plot

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Performance en Centro de ayuda y File Exchange.

Productos

Versión

R2022a

Preguntada:

el 5 de Mayo de 2022

Comentada:

Rik
el 9 de Mayo de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by