Surface fit approximation for x,y and z data
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
Cris LaPierre
on 12 Mar 2021
Edited: Cris LaPierre
on 12 Mar 2021
Do the values in your vector X correspond to the columns in Z? Do the values in Y correspond to the rows of Z? Is so, you shouldn't need to interpolate.
Instead, you would use meshgrid to create X and Y matrices the same size as Z.
Matt J
on 12 Mar 2021
Also, the parameters g, h, i do not appear in your function model.
Alessandro Maria Laspina
on 13 Mar 2021
Edited: Alessandro Maria Laspina
on 13 Mar 2021
Alessandro Maria Laspina
on 21 Mar 2021
Answers (1)
Cris LaPierre
on 13 Mar 2021
0 votes
3 Comments
Alessandro Maria Laspina
on 15 Mar 2021
Cris LaPierre
on 15 Mar 2021
I don't see how using interp2 meets all your requirements.
Alessandro Maria Laspina
on 20 Mar 2021
Categories
Find more on Interpolation 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!