Curve fitting function (fit) error

I am using function "fit" to fit a surface to my data. I have a 3 dimentional data , z(x,y). I use the function as below: surfacefit=fit([x y],z,'polyll') I am sure both my x and y are column matrix and have the same dimension. But i get this error : Error using fit>iFit (line 133) Y must be a column vector.
Error in fit (line 109) [fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...

回答 (3 件)

Di Xu
Di Xu 2016 年 9 月 8 日

2 投票

Hi,
I think your z is a matrix, right?
But in fit([x y],z,'polyll'), z must be a column.
So you can use the reshape function http://nl.mathworks.com/help/matlab/ref/reshape.html You can simply reshape z into a column by z=reshape(z,[],1). Of course, you should accordingly change x and y, in order that they have the same disension as z, i.e. for every element in z, its coordinates should be at the according position in x and y.
Then you can run fit.
Walter Roberson
Walter Roberson 2012 年 11 月 2 日

1 投票

surfacefit=fit([x(:), y(:)],z(:),'polyll')

3 件のコメント

sepideh
sepideh 2012 年 11 月 2 日
Hi, thanks for the answer, but i still get the same error.
Susarla
Susarla 2015 年 2 月 5 日
Many Thanks for this answer
chuenkiong
chuenkiong 2023 年 3 月 15 日
Thank you so much!

サインインしてコメントする。

Kutsop
Kutsop 2016 年 5 月 12 日

0 投票

I had the same problem. "Y" in this case is the second variable called in fit("X","Y","fittype") where for a 3D fit "X" is usually "[x,y]" and "Y" is "z" or in other words fit("[x,y]","z","fittype"). So if for z is a 64 by 64 array and x = 1:64; y = 1:64; then you need to make both x and y 64 by 64 arrays with repeated column and row values respectively, and then use reshape to make x,y,z all 4096 by 1 column vectors. You bassically need to unravel your 3D array.

カテゴリ

ヘルプ センター および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

質問済み:

2012 年 11 月 2 日

コメント済み:

2023 年 3 月 15 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by