How can I make user defined x-values with corresponding y-values?
2 views (last 30 days)
Show older comments
I have two graphs with the same x-axis, years from 2001 to 2010. All I need is to have the user change which years, to and from, that they want to see, and have the graphs display that interval with all of the y-values. Essential it will zoom in on those parts of the graphs.
I can get the user defined x-values but I don't know how to match the y-values here with the graphs.
plot((startyear:endyear),y)
0 Comments
Accepted Answer
Star Strider
on 9 May 2014
3 Comments
Image Analyst
on 10 May 2014
What do you mean "access"? You have the y array, don't you? You must because you plotted it. You can "access" it by specifying indices like
yInRange = y(startYearIndex : endYearIndex)
Star Strider
on 10 May 2014
My pleasure!
The y-values will take care of themselves. Use ylim in the axis statement:
axis([xmin xmax ylim])
MATLAB automatically calculates xlim and ylim (and zlim if you’re doing 3D plots). If you only want to override one ( xlim in your situation ), you can simply specify the other as the MATLAB-calculated default.
You already have access to the y-values, since you used them to generate your plot.
More Answers (0)
See Also
Categories
Find more on Line Plots 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!