Surface fit approximation for x,y and z data
13 views (last 30 days)
Show older comments
I have an x and y vector, of sizes n and m respectively. I also have a z matrix of size n by m.
I am trying to do one of the following, preferably both:
- interpolate for given x and y values to find the value of z
- find a 2D function with inputs x and y using fit
In either scenarios, I am not sure whether I can do this since my x and y's are of different sizes. For the second option, which isn't as straight forward, I have the following code:
fitType=fittype(@(a,b,c,d,e,f,g,h,i,x,y) ...
(a+b*x+c*x^2)+(d+e*x+f*x^2)*sin(y)+(g+h*x+i*x^2)*cos(y));
fitZ=fit([M,aoa],Z,fitType,'StartPoint',ones(1,9));
where my fit function, as seen in the code, is: (a+b*x+c*x^2)+(d+e*x+f*x^2)*sin(y)+(g+h*x+i*x^2)*cos(y). The constants a,b,c,d,e,f,g,h,i are the one which I want fit to find me. Unfortunately, this does not work for different sized arrays.
EDIT: I've found a solution that may work but it turns out I cannot call the independent variables as [M,aoa]. The code is now:
myfittype = fittype('(a+b*Mx+c*Mx^2)+(d+e*Mx+f*Mx^2)*sin(aoax)+(g+h*Mx+ii*Mx^2)*cos(aoax)',...
'dependent',{'Z'},'independent',{'Mx','aoax'},...
'coefficients',{'a','b','c','d','e','f','g','h','ii'});
[Mmesh,aoamesh]=meshgrid(M,aoa);
fitCL=fit([M,aoa],Z,myfittype);
This returns the following error:
Operator '<' is not supported for operands of type 'fittype'.
Error in fit (line 7)
if dim_x < m
4 Comments
Answers (1)
See Also
Categories
Find more on Fit Postprocessing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!