How to get details from a plot?
Show older comments
I have a plot.For each increment of 1 in x value I have y value. But I need y values for 0.1 increment in x-axis. How can I extract this from the plot itself.Please help me.

3 Comments
Walter Roberson
on 2 Nov 2015
What form is the plot in? Is a .jpg? Is it a .fig? Is it currently displayed as graphics in MATLAB? If it is currently being displayed in MATLAB, is there a reason why you cannot perform calculations based on the data that was used to create the plot, without having to go through the extra step of retrieving that data from the plot?
anna lakshmi
on 2 Nov 2015
Walter Roberson
on 2 Nov 2015
Analogy:
Suppose it is your practice to start with a couple of pieces of paper and a box, and you throw the pieces of paper in the box and then you ask me to get the pieces of paper out of the box and do something with them. And my question is "Why can't I have the pieces of paper before you throw them in the box?"
newx = min(x):0.1:max(x);
newy = interp1(x, y, newx);
I think you will find that somewhat easier than getting the values "from the plot itself"...
x205left = newx(find(newy>=205, 1, 'first'));
x205right = newx(find(newy<=205, 1, 'last'));
width205 = x205right - x205left
Answers (1)
Alternately to Walter's solution based on interpolation to a particular resolution, solve directly for the locations wanted rather than simply the chosen 0.1 approximation resolution --
>> y=600*normpdf(-3:0.4:3,0,1); % some dummy data that approximates yours as a peak
>> ix=find(abs([0 diff(y>205)])==1); % find the two crossings of interest
>> x205left=interp1(y(1:ix(1)),1:ix(1),205)
x205left =
7.1460
>> x205right=interp1(y(ix(2)-1:end),ix(2)-1:length(y),205)
x205right =
9.8540
>>
Can also use Walter's find to locate the two initial positions, I just illustrated another useful technique for location positions in curves that's extremely useful on occasion albeit not "quite so much" here as there are only two points.
Only real "trick" here is that must do the interp1 call on the two regions as it will only handle strictly increasing/decreasing patterns whereas the full curve is double valued in x.
The other option in the above is that you can also use either higher-ordered or perhaps spline interpolation to perhaps better approximate the underlying curve--this could be evaluated for the example above where the exact solution is available for comparison.
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!