I have 4-5 subplots of timeseries data and scatter plots in a MATLAB figure whose x axes are linked. The data is quite long and I've zoomed into a small portion of the figure.Now I want to export just the data contained in this zoomed in portion to work-space as variables. Is it possible?
For example, the following is the plot for the full dataset.
The following is the zoomed in portion,
Now I want to export all the variables or time-section of the variables corresponding to the above zoomed in portion to workspace.
Building off of Ratbert's comment, let's set up a sample plot to play around with.
I'm going to assume you have MATLAB R2014b or newer, which is where MATLAB switched graphics handles to objects. If you have an older version you can swap all of my dot notations with
get
andset
calls, where appropriate.Now with this initial plot, if we enter
h.myaxes.XLim
orget(h.myaxes, 'XLim')
, we return:Now if we zoom in arbitrarily and make the same call, we get something different. In my case:
Now it's up to you how you want to use this information to window your data. A very basic method would be to use
find
to get the indices of the closest data points to these limits.For example:
Returns
[newmin, newmax]
of:I used
floor
andceil
here because I know my data is integers, your criteria may be different but the process is the same. Hopefully this is enough to get you started.