How I can get specific values from Matlab Figure

﹥>﹥吖頭↗ 提交于 2019-12-04 06:54:15

问题


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,

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.


回答1:


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.




回答2:


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



回答3:


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.



来源:https://stackoverflow.com/questions/25058329/how-i-can-get-specific-values-from-matlab-figure

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