如何从Matlab图中获取特定值

如何从Matlab图中获取特定值,matlab,plot,matlab-figure,Matlab,Plot,Matlab Figure,我想从Matlab图形中得到一些特定的值。值的数量可以是3、5、10、50或任意N个整数。就像在示例图片中一样 我想得到A,B,C的值,形式为A=(430,0.56) A、 B、C不是绘图的一部分。我只是在Photoshop中写下它们,帮助澄清问题 注意:每次执行代码时,输入值可能不同。 输入值(图形值)的长度也可以每次更改。首先打开图形,然后使用 line = get(gca, 'Children'); % Get the line object in the current axis

我想从Matlab图形中得到一些特定的值。值的数量可以是3、5、10、50或任意N个整数。就像在示例图片中一样

我想得到A,B,C的值,形式为A=(430,0.56)

A、 B、C不是绘图的一部分。我只是在Photoshop中写下它们,帮助澄清问题

注意:每次执行代码时,输入值可能不同。


输入值(图形值)的长度也可以每次更改。

首先打开图形,然后使用

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.
要在横坐标大于或等于
xi
的点处获得值
yi
,可以编写

id = find(x>=xi, 1, 'first');   % On the opposite try find(x<=xi, 1, 'last');
yi = y(id);
要提取横坐标为
x1
x2
的点之间的值,可以采用这两种策略。用你能写的第一本书

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

如果你有一张图表,你只想找出图表上任意点的值,你可以使用这个函数,或者到目前为止,最简单的解决方案就是使用内置在图形窗口中的交互式工具。

hc=get(gca,'children');
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);
data=get(hc,{'xdata','ydata'}); t=数据{1}; y=数据{2}; tA=250;tB=1000;%tA是起始点,tB是数据的最后一点,如图所示
yinterval=y(t>=tA&t这些点是什么(A,B,C)等等?它们实际上是作为一个单独的系列绘制的吗?如果它们没有标记在图表上,请查看
ginput
函数。a、B、C或不是绘图的一部分。我只是在Photoshop中编写它们来理解这个问题。如果我想从a点到B点取值的范围呢?但是你没有解释代码。比如“xi”是什么对不起,我认为代码是不言自明的。我添加了一些注释。一些解释会改进这个答案。
xReduced = x1:step:x2;   % As an alternative you can use linspace(x1, x2, nPoints);
yReduced = interp1(x, y, xReduced);
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);