Surface fitting problem
3 views (last 30 days)
Show older comments
I have a data set as z=fun(x,y). I can compute z value at any (x,y) at certain range of x and y. What I need is to fit z value as an explicit function of x and y. So I chose a selected data x(m) and y(n), and get a z matrix as z(m,n). Then I try to use sftool to do the fitting.
The problem is I cannot input like sftool(x,y,z) as a valid command. It says z has to be a vector. I can not select z as output in the interactive window. Can someone give me some help on this please?
0 Comments
Answers (3)
Andreas Goser
on 16 Mar 2011
I used your question to take a first look at surface fitting. I know the CFTOOL quite well, but not the SFTOOL.
It looks the the charming thing here is that you have not to interpolate 2d data anymore (the old GRIDDATA pain), but can work with x,y,z measurements and just go ahead for fitting.
But for you, as you seem to have already complete z data for all x-y combinations, this looks like you need to go the step back and create x,y and z vectors like
x=[1 2 3 1 2 3 1 2 3]
y=[1 1 1 2 2 2 3 3 3]
z=[1 2 1 2 0 2 0 2 1]
For your case, you can work with REPMAT for getting x and y.
This is at least my idea working with this tool for the first time.
0 Comments
Jiro Doke
on 16 Mar 2011
I assume you are using version R2010a or older. Your syntax should work for the newer versions.
You seem to have vectors for x and y , and a matrix for z. To use sftool, you need 3 variables with the same number of elements, and they need to be vectors (In R2010b, they do not need to be vectors).
From your description, the row number of your z matrix corresponds to your x element and the column to your y element. You just need to set up your grid matrix for x and y using meshgrid.
[Y, X] = meshgrid(y, x);
sftool(X(:), Y(:), z(:))
Note the order of x and y in the meshgrid function. I used this order to get the corresponding rows and columns correct. Also (:) allows you to expand a matrix to a vector.
0 Comments
jean-philippe bedard
on 8 Apr 2016
I am trying to do the same but failing after trying Jiro Doke suggested vector solution, my matlab 2010a crashes when I select the Zvector in sftool. Anyone could have ideas that I could explore to solve this?
0 Comments
See Also
Categories
Find more on Get Started with Curve Fitting Toolbox 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!