简体   繁体   English

2d多项式拟合表数据MATLAB

[英]2d polynomial fitting to table data MATLAB

I am trying to use 2D polynomial fitting for my table data, my data format is exactly like the link below: http://www.mathworks.de/help/toolbox/curvefit/brx2ldg-1.html#bso46rp-1 我正在尝试使用2D多项式拟合来处理我的表数据,我的数据格式与下面的链接完全相同: http//www.mathworks.de/help/toolbox/curvefit/brx2ldg-1.html#bso46rp-1

I mean I have vector X with length n , Y with length m and m*n Matrix Z , I would like to fit 5 degree 2d polynomial to my data, 我的意思是我有长度为n向量X ,长度为m Ym*n矩阵Z ,我想将5度2d多项式拟合到我的数据中,

I am wondering that is there any syntax in MATLAB for solving this problem? 我想知道MATLAB中有没有解决这个问题的语法? like SFIT command in IDL, http://star.pst.qub.ac.uk/idl/SFIT.html 比如IDL中的SFIT命令, http: //star.pst.qub.ac.uk/idl/SFIT.html

I have cftool and sftool , but it seems that they don't work for this purpose or most probably I don't know how to employ them. 我有cftoolsftool ,但似乎它们不能用于此目的,或者很可能我不知道如何使用它们。

and I know that there some m.file which people share in MATLAB Mathworks file exchange, please if you know one works properly, suggest me. 我知道人们在MATLAB Mathworks文件交换中有一些m.file,如果你知道一个正常工作,请告诉我。

I'd appreciate any help and comment. 我很感激任何帮助和评论。

You can use polyfitn from file exchange and re-format your data in order to have 3 MxN x,y,z vectors. 您可以在文件交换中使用polyfitn并重新格式化数据,以便拥有3个MxN x,y,z向量。

Example : 示例

Assume you have a table data of the form 假设您有表格的表格数据

N = 100; M = 80;
x = linspace(0, 1, M);
y = linspace(0, 1, N).';
z = bsxfun(@franke, x, y);

Create meshgrid for x, and y instead 为x创建meshgrid ,而改为y

N = 100; M = 80;
[x, y] = meshgrid(0:1:N, 0:1:M);
z = bsxfun(@franke, x, y);

(Note that unique(x) and unique(y) will give you the original linspace values of your table rows and columns.) (请注意, unique(x)unique(y)将为您提供表行和列的原始linspace值。)

Use polyfitn to get the 5-degree polynomial coefficients 使用polyfitn得到5次多项式系数

p = polyfitn([x(:),y(:)], z(:), 5);

You can additionally convert the result into a symbolic form to view the polynomial using the provided polyn2sym(p) 您还可以将结果转换为符号形式,以使用提供的polyn2sym(p)查看多项式

>> pretty(polyn2sym(p))

                      5                           4                             4                         3   2
     90264379051097 X1         2537627280433653 X1  X2       7778045812403061 X1       6982058230382053 X1  X2
- ------------------------- - -------------------------- + ------------------------ - -------------------------- + ...
  2417851639229258349412352   38685626227668133590597632   604462909807314587353088   77371252455336267181195264

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM