Generate Plot Based on Interval Data
Show older comments
How would I generate a plot if I have data from intervals. I'm not sure if 'interval' is the right technical term.
What I mean is I have data like this
[210 320 430 250 110 ...] <-represents distance
[30 50 10 20 40...] <-represents speed limit
For the first 210 metres, the speed limit is 30km/h. For the subsequent 320m, the speed limit is 50km/h, and so on.
It would look like the blue line in this figure.

Is there a simple way to plot such data? Of course, I can set a loop and interpolate the speed at a distance interval of say, 1 metres. Then subsequently, use the plot(distance,speed) function. But would there be a more elegant way?
Subsequently, I would also want to modify the curve. It's impossible for a car to follow the blue speed curve as it requires infinite acceleration/deceleration. I would like to limit the speed curve to the red curve, by specifying a constant acceleration/deceleration rate of e.g. 1m/s^2.
Would there be a simple way to do this as well?
I've thought of a long method, which is to construct the red slope using y=mx+c. Then define which sections the y=mx+c is valid for, and lastly take the minimum of the blue lines and y=mx+c at every interval, say 1 metres. And this would be repeated for every red slope which exists.
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

