How to use griddata() with independent z component
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
d12 =
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.
d14 =
-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
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 then plot the result.
So then I tried to use the griddata function and was not successful, here is my attempt.
%--------Start-------------------
[holdX,holdY,holdZ]=[d12(:,1),d12(:,2),d12(: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]=[d14(:,1),d14(:,2),d14(: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!
0 Kommentare
Antworten (1)
Aurele Turnes
am 5 Aug. 2014
It seems like you are trying to get a surface plot in 3 dimensions from 3 n-dimensional vectors (x,y,z). This is not possible in general, because there could be many different surfaces that pass through those points. You might want to use the scatter3 function to visualize your data as follows:
figure
scatter3(d12(:,1),d12(:,2),d12(:,3))
hold on
scatter3(d14(:,1),d14(:,2),d14(:,3))
0 Kommentare
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!