3D Surface plot with spline interpolation

24 views (last 30 days)
Joseph
Joseph on 24 Jul 2014
Answered: Joseph on 25 Jul 2014
I am trying to plot 2d data in the 3d plane to create a surface that represents the effects of changing z.
Data: Each column of my data represents a X, Y, and a Z value respectively.
@ z=12 I have the data.
d =
0.3000 0 12.0000
0.2898 0.0776 12.0000
0.2598 0.1500 12.0000
0.2121 0.2121 12.0000
0.1500 0.2598 12.0000
0.0776 0.2898 12.0000
0.0000 0.3000 12.0000
-0.1165 0.4347 12.0000
-0.2250 0.3897 12.0000
-0.4243 0.4243 12.0000
-0.7794 0.4500 12.0000
-0.8693 0.2329 12.0000
-0.9000 0.0000 12.0000
-0.8693 -0.2329 12.0000
-0.7794 -0.4500 12.0000
-0.6364 -0.6364 12.0000
-0.4500 -0.7794 12.0000
-0.2329 -0.8693 12.0000
-0.0000 -0.9000 12.0000
0.2329 -0.8693 12.0000
0.4500 -0.7794 12.0000
0.5303 -0.5303 12.0000
0.3897 -0.2250 12.0000
0.4347 -0.1165 12.0000
0.3000 -0.0000 12.0000
@ z=14 I have the data.
d =
-0.2121 0.2121 14.0000
-0.6495 0.3750 14.0000
-0.8693 0.2329 14.0000
-0.9000 0.0000 14.0000
-0.8693 -0.2329 14.0000
-0.7794 -0.4500 14.0000
-0.6364 -0.6364 14.0000
-0.4500 -0.7794 14.0000
-0.2329 -0.8693 14.0000
-0.0000 -0.6000 14.0000
0.0388 -0.1449 14.0000
@ z=16 I have the data.
d =
-0.8693 0.2329 16.0000
-0.9000 0.0000 16.0000
-0.8693 -0.2329 16.0000
-0.7794 -0.4500 16.0000
-0.6364 -0.6364 16.0000
In order to use Matlab's built in surface command I need to have the different levels of Z to be of equal dimensions. Therefor I am trying to interpolate the data so that each set of z values have 50 rows and give the surface a round effect. Unfortunately I am not able to successfully do this. I have looked throughout Matlab Central to find a similar problem with a solution and was not able to find anything. Could you guys help me out or point me in the right direction please?

Answers (1)

Joseph
Joseph on 25 Jul 2014
Alright so I tried to use the griddata function and was not successful, here is my attempt.
%--------Start-------------------
[holdX,holdY,holdZ]=[d(:,1),d(:,2),d(:3)] %This is short hand for a function
xstep=(abs(min(holdX)-max(holdX)))/50;
xgrid=[min(holdX):xstep:max(holdX)];
ystep=(abs(min(holdY)-max(holdY)))/50;
ygrid=[min(holdY):ystep:max(holdY)];
zz=zeros(1,length(xgrid)); zz(1,:)=16; zgrid=zz;
x(:,1)=xgrid; y(:,1)=ygrid; z(:,1)=zgrid;
X(:,1)=holdX; Y(:,1)=holdY; Z(:,1)=holdZ;
clearvars holdX holdY holdZ xstep ystep zstep xgrid ygrid zgrid
%----------Round 2--------------------
[holdX,holdY,holdZ]=[d(:,1),d(:,2),d(:3)] %This is short hand for a function
xstep=(abs(min(holdX)-max(holdX)))/50;
xgrid=[min(holdX):xstep:max(holdX)];
ystep=(abs(min(holdY)-max(holdY)))/50;
ygrid=[min(holdY):ystep:max(holdY)];
zz=zeros(1,length(xgrid)); zz(1,:)=14; zgrid=zz;
x(:,2)=xgrid; y(:,2)=ygrid; z(:,2)=zgrid;
X(:,2)=holdX; Y(:,2)=holdY; Z(:,2)=holdZ;
%-----------------Plot----------------
T=griddata(X,Y,Z,x,y,z,'cubic')
%as soon as I run griddata I get an error "Invalid number of input arguments."
I dont think I know how to generate the grid data correctly because I think I need another vector 'v' that corresponds x to X, y to Y and z to Z. Not really sure, please help me out guys if you can. Thank You!

Products

Community Treasure Hunt

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

Start Hunting!