-1

I want to get some specific values from a Matlab Figure. The number of values can be 3, 5, 10, 50 or any N integer. Like in sample pictures,

Pic1 Pic2

I want to get values of A, B, C. in form of e.g A=(430,0.56).

A,B,C are not the part of Plot. I just wrote them in Photoshop help clarify the question.

Note: On every execution of the code input values can be different.

The length of the input values (Graph Values) can also change every time.

Cecilia
  • 4,512
  • 3
  • 32
  • 75
Adnan Ali
  • 2,851
  • 5
  • 22
  • 39
  • What are those points (A, B, C) etc? Are they actually plotted as a separate series? Check out the `ginput` function if they are not marked on the chart already – Dan Jul 31 '14 at 12:03
  • A,B,C or not the part of Plot. I just Wrote them in Photoshop to make Understand the Question. – Adnan Ali Jul 31 '14 at 12:28

3 Answers3

1

First open the figure, then obtain the x and y coordinates of the line with

line = get(gca, 'Children');   % Get the line object in the current axis of the figure.
x = get(line, 'XData');   % Get the abscissas.
y = get(line, 'YData');   % Get the ordinates.

To obtain the value yi at the point with abscissa greater or equal then xi you can write

id = find(x>=xi, 1, 'first');   % On the opposite try find(x<=xi, 1, 'last');
yi = y(id);

Or you can do a linear interpolation

yi = interp1(x, y, xi);

To extract the values between the points with abscissa x1 and x2 you can follow both strategies. With the first you could write

ids = find(x>=x1 & x<=x2);
xReduced = x(ids);   % A subset of x.
yReduced = y(ids);   % A subset of y.

The first line intersects the set of points that follow x1 with the set of points that precede x2, and the return the indices. If you choose to interpolate tou can construct a new set of points, and interpolate over that set.

xReduced = x1:step:x2;   % As an alternative you can use linspace(x1, x2, nPoints);
yReduced = interp1(x, y, xReduced);
Jommy
  • 1,020
  • 1
  • 7
  • 14
0

If you have a chart and you just want to find out the values of arbitrary points on the chart you can use the ginput function or by far the simplest solution is to just use the interactive data cursor built into the figure window.

Dan
  • 45,079
  • 17
  • 88
  • 157
0
hc=get(gca,'children');
data=get(hc,{'xdata','ydata'});
t=data{1};
y=data{2};
tA=250;tB=1000; %tA is starting Point and tB is the last point of data as ur figure
yinterval=y(t>=tA & t<=tB);
display(yinterval);

Try this code, Its working for me Code is according to Time and Y figure.

ALI
  • 339
  • 3
  • 11