从更精细的比例图中提取数据点 [英] Extracting data points from a plot on a finer scale
问题描述
我想从Matlab中的绘图图中提取数据.因此,我做了以下事情:
I want to extract data from a plotted graph I have in matlab. As such, I did the following:
f = openfig('spline.fig');
xdata = get(gco, 'xdata');
ydata = get(gco, 'ydata');
这确实分别为我提供了x
和y
的数据点,但是在每个点之间都有一个0.5
步长(例如 1、1.5、2、2.5 ... ).我希望能获得比该数据更好的数据点(例如例如 1、1.1、1.2、1.3、1.4 ...),以及与这些x坐标相对应的y坐标.我该怎么办?
This does give me the data points of x
and y
respectively, but with a step of 0.5
between each points (e.g 1, 1.5, 2, 2.5...). I was hoping to get finer data points than that (e.g 1, 1.1, 1.2, 1.3, 1.4...), and the corresponding y-coordinates to these x-coordinates. How can I do this?
推荐答案
您获取ydata
的方式对我不起作用,我会使用:
The way you got your ydata
didn't work for me, I would use:
open testfigure.fig
D = get(gca, 'Children');
ydata = get(D, 'YData');
我获得的ydata
包含用于绘制图形的原始y数据.
The ydata
I obtained contains the original y-data used to plot the figure.
现在,如果您需要更精细的数据分辨率,则必须自己进行插值.
这是有关如何将ydata
插值为0.1分辨率的简短示例:
Now, if you need a finer resolution in the data you will have to interpolate that yourself.
Here's short example of how to interpolate this ydata
to a resolution of 0.1:
-
定义新的x值xi以查找y的值
Define new x values xi to find y values for
xi = 0:0.1:10;
对ydata
进行插值以在xi
处找到新的yi
值:
Interpolate ydata
to find new yi
values at xi
:
yi = interp1(xdata, ydata, xi); %// Using the default "linear"
您应该阅读要使用的方法(例如 样条),这取决于您的数据和要求.
You should read up on the kind of method you want to use (e.g. nearest neighbour, spline), this depends on your data and requirements.
这篇关于从更精细的比例图中提取数据点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!