How I can get specific values from Matlab Figure

為{幸葍}努か 提交于 2019-12-02 12:54:56
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.

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);

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!