skip to Main Content

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.

3

Answers


  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);
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search