1

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?

Prometheus
  • 153
  • 3
  • 12
  • 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 Aug 07 '14 at 13:39
  • I need it just for visualization. I don't need an equation. Any kind of smooth surface interpolation would do. – Prometheus Aug 07 '14 at 13:41
  • 1
    If you need it just for visualization just surf(X,Y,Z) – Ander Biguri Aug 07 '14 at 13:42
  • surf can only be used when you have uniformly spaced x and y data. It says Z needs to be a matrix. – Prometheus Aug 07 '14 at 14:22
  • Well, a quick google search gives you the answer AND the code.http://blogs.mathworks.com/videos/2007/11/02/advanced-matlab-surface-plot-of-nonuniform-data/ – Ander Biguri Aug 07 '14 at 14:25
  • possible duplicate of [Matplotlib plotting non uniform data in 3D surface](http://stackoverflow.com/questions/12730436/matplotlib-plotting-non-uniform-data-in-3d-surface) – Ander Biguri Aug 07 '14 at 14:26

2 Answers2

0

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

shimizu
  • 998
  • 14
  • 20
0

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

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120