如何从Curvefit中提取残差 [英] How to extract residuals from curvefit

查看:139
本文介绍了如何从Curvefit中提取残差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Matlab R2016a中使用曲线拟合来找到两个数组之间的最佳拟合.一个数组代表给定纬度和经度的某个值,另一个数组代表该值的收集日期.

I'm using curve fit in Matlab R2016a to find the best fit between two arrays. One array represents a certain value at a given latitude and longitude and the other array represents the date that value was collected.

在使用曲线拟合工具时,我能够找到一条最佳拟合线并绘制残差.残差是我关心的全部-但是,当我将残差导出到工作区时,它们表示为一列数字.如果没有识别该残差与原始数组的关系的信息(即每个残差对应于哪个X,Y对?),这对我没有帮助

In using the curve fit tool I'm able to find a line of best fit as well as to plot the residuals. The residuals are all I care about-- however, when I export the residuals to the workspace they are represented as one column of numbers. This isn't helpful to me without the identifying information of that residual's relationship to the original arrays (i.e., which X,Y pair does each residual correspond to?)

曲线拟合工具中残差图中的数据正是我想要的.有没有一种方法可以使它变得可用?

The data from the residuals graph in the curve fit tool is exactly what I want. Is there a way to export this in a manner that makes it usable?

推荐答案

cftool本质上使用fit.您可以做进一步探索拟合及其残差的操作,是将拟合导出到您的工作空间.通过曲线拟合工具"窗口顶部的适合"菜单执行此操作,然后选择保存到工作区".使用此拟合对象(对于曲线为cfit或对于曲面为sfit),您可以进行与曲线拟合工具相同的分析,并且可以做更多的事情.

The cftool uses fit at its heart. What you can do to further explore the fit and its residuals is export the fit to your workspace. Do this through the 'Fit' menu at the top of the Curve Fitting Tool window, then select 'Save to Workspace'. Using this fit object (a cfit for a curve or an sfit for a surface), you can do the same analyses and more as with the curve fitting tool.

让我说明如何获得拟合,创建残差图以及如何计算残差.生成的图像如下所示.在代码中,residuals变量包含与xy中属于每个样本对的每个元素的拟合残差.

Let me illustrate how to obtain a fit, create a plot of the residuals and how to calculate the residuals. The resulting image is shown below. In the code, the residuals variable contains the residuals of the fit with each element belonging to each sample pair in x and y.

% Generate data
rng default
x = sort(rand(10, 1));
y = randn(size(x)) - 3*x;

% Fit a line
fitted = fit(x, y, fittype('poly1'));

% Plot fitted line with data
figure
subplot 311
plot(fitted, x, y)

% Plot residuals
subplot 312
plot(fitted, x, y, 'residuals)')
ylabel residuals

% Get residuals
residuals = y - fitted(x);

% Create stem plot of residuals
subplot 313
stem(x, residuals)
legend residuals
xlabel x
ylabel residuals

这篇关于如何从Curvefit中提取残差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆