1
votes

I have 10 sets of 3D points. Each set represents points on a smooth curve. I can easily fit a curve to each set in Matlab and get 10 curves. How can I now fit a surface through these curves in Matlab?

2
What kind of surface? Do you have an equation you want to fit or you just want something that goes trough all? If it is the second you should have a look to Bicubic spline surfaces for example. You can make patches of surfaces. This is how images get resized in computers (although usually its with biliniear surfaces instead)Ander Biguri
I need it just for visualization. I don't need an equation. Any kind of smooth surface interpolation would do.Prometheus
If you need it just for visualization just surf(X,Y,Z)Ander Biguri
surf can only be used when you have uniformly spaced x and y data. It says Z needs to be a matrix.Prometheus
Well, a quick google search gives you the answer AND the code.blogs.mathworks.com/videos/2007/11/02/…Ander Biguri

2 Answers

0
votes

If you have the Curve Fitting Toolbox, it's easy to fit a surface to 3 x,y,z vectors using the fit function. Here's some example code that fits a polynomial surface to random points. You can define your own fitting function if you like or check out the other fitTypes they have for surfaces. Here's the documentation for fit.

x = rand(10,1);
y = rand(10,1);
z = rand(10,1);
f = fit([x,y],z,'poly23');
figure;
scatter3(x,y,z,'r','fill'); hold on;
plot(f);

Here's what the result looks like (yours may vary, since random points): enter image description here

0
votes

If you dont have curvefiting toolbox you cando:

x=rand(100,1)*16-8;                     % Use your data instead
y=rand(100,1)*16-8;
r=sqrt(x.^2+y.^2)+eps;
z=sin(r)./r;
%
xlin=linspace(min(x),max(x),33);        % Create x,y linear space
ylin=linspace(min(y),max(y),33);
[X,Y]=meshgrid(xlin,ylin);              % Create mesh [x y]
Z=griddata(x,y,z,X,Y,'cubic');          % Interpolate with bicubic functions            
%
mesh(X,Y,Z); % interpolated             % Fancy plots for demosntration
 hold on
plot3(x,y,z,'.','MarkerSize',15)
% surf(X,Y,Z)                           % use this one to get the standard surf

To get:

enter image description here