surface fitting1

3 views (last 30 days)
krivan
krivan on 3 Jun 2011
Hi,
I'd like to ask for help regarding surface fitting and I have very little experience in Matlab.
I have a Z 77x77 matrix.
If I use surf(Z) I can plot it without problem.
I would like to interpolate Z but I couldn't get it right neither with the sftool nor with the gridfit.
If I call sftool I don't even have an option to select this Z matrix. I've read the manuals but it is still unclear how I could do this.
So the question is how to use this interactive sftool if I have a 77x77 large Z matrix [measurement data] and I want to interpolate or somehow fit it.
Thanks, Krivan

Accepted Answer

John D'Errico
John D'Errico on 3 Jun 2011
Why use gridfit, or for that matter, the surface fitting tool? It is already a surface, on a regular grid. Use interp2, a tool designed for exactly that purpose.
help interp2
Edit: If x and xi are identical, then why are you trying to interpolate anyway? You would get out the input array even if you had called interp2 properly! It does not sound as if you are trying to do interpolation at all.
As far as the surface goes, if it is too noisy and you just want to make it less so, then do some smoothing. A simple solution there is to use a convolution tool, although then you need to deal with edge effects. Easier is to use gridfit, with a larger than normal value for the smoothness parameter.
[xmesh,ymesh] = meshgrid(x,y); zgrid = gridfit(xmesh(:),ymesh(:),z(:),x,y,'smoothness',k);
By default, the smoothing parameter is 1, a value which will yield relatively little smoothing. Try 2 or 5 or 10. Pick a value that makes you happy.

More Answers (3)

Rob Graessle
Rob Graessle on 3 Jun 2011
To do surface fitting you need to define your X and Y data vectors.
X=1:77; Y=1:77; % Or any other vectors of 77 points
Then you can use SFTOOL by supplying X, Y and Z as the data vectors.

krivan
krivan on 3 Jun 2011
Hi,
thank you for your answer!
Basically what I did here is the following [everything in Matlab command line]
1.
x=0:76 % 1x77 double
y=0:76 % 1x77 double
z=[...] % ... symbolises the z matrix copied&pasted from a text file 77x77
sftool (x(:),y(:),z(:))
Here in the popup window I automatically got x1 as x vector, y1 as y vector and z1 as z. The problem here is that I don't see anything appearing in the 3D window.
2.
I tried interp2 too as follows:
x=xi=0:76 % 1x77 double
y=yi=0:76 % 1x77 double
zi = interp2(x,y,z,xi,yi,'cubic')
mesh(xi,yi,zi)
And here I get the error message: ??? Error using ==> mesh at 80 Z must be a matrix, not a scalar or vector. This error message comes obviously because my zi become a 1x77 vector from the 77x77 matrix.
I have this data set which I couldn't attach here. If I surf(z) it, I get a noisy wave-like surface and what I am trying to achieve is to fit a kind of 3D plane onto the noisy surface.
Can you please advise how to proceed. For some reason interp3 didn't work for me either.
thanks!
P.s. @John: answering your question, I used Labview for a long time and had to change to Matlab only very recently. So I don't know the tools here yet this is why I tried every possible solutions, gridfit+sftool...
  1 Comment
John D'Errico
John D'Errico on 3 Jun 2011
(See my edited answer)

Sign in to comment.


krivan
krivan on 23 Jun 2011
This gridfit works fine with the smoothness 10. The surf(zgrid) gives a really nice smoothened surface. Thank you for your help!

Categories

Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!