How to plot an x value using for loop from an input?
3 views (last 30 days)
I am working on a project, and I am trying to graph the second half of the descent rate where the y axis is feet and the x axis is minutes. I want it to plot a point every minute, where it decreases 3000 feet per minute starting at the crusing altitude, down to 10,500 feet, and it plots a point every minute. So far I have got the ascent rate to work and the first half of the descent rate to work. Everytime I run it, I get an error about the indexing. 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, sm=starting minutes, yd=y-axis point in first half descent, xd=x-axis point in first half descent, dcx=decent y values, dcy=descent x values. The points should be (mdd,13500) (minutes-9,16500) (minutes-10,19500)(minutes-11,22500) etc to A1. Also, how do I get the dots connected to each other for the first half of the descent rate?
title('Time vs Height')
the cyclist on 8 May 2022
Edited: the cyclist on 8 May 2022
I have to admit that I did not fully understand your explanation. But I can tell you the specific reason you are getting an indexing error from that code. Here is the first part of your code, with lines commented out if they are not directly relevant to the indexing issue.
Notice that dcy is an empty vector. The reason is that you are defining dcy as
127 : -1 : 30000
which is empty because you cannot get to 30000 from 127 in steps of -1. :-)
That definition is surely not what you intend. (But I could not glean what you did intend.)
William Rose on 9 May 2022
@Hunter Nau, You are plotting each point of the descent as a separate series, which is why you cannot connect them. This also makes the script cumbersome. Make a single vector of all the times, from start to finish, and a corresponding vector of altitudes. The time spacng does not have to be uniform. In the example below, I used a final altitude different than the initial altitude, just to show that it can be done.
ra=2000; %ascent rate (ft/min)
rd=-3000; %descent rate (ft/min)
A0=0; %initial altitude
A1=30000; %crusing altitude (ft)
Af=6000; %final altitude
Tf=135; %final time
da=(A1-A0)/ra; %duration of ascent
dd=(Af-A1)/rd; %duration of descent
Td=Tf-dd; %time descent begins
Try it. Good luck.