mallow
mallow

Reputation: 83

3D plot matlab with 3 equally sized vectors

I have three vectors, X, Y, and Z. All of equal length (20000,1). I want to plot all three in a 3d plot. I have tried using surf and plot3 but to no avail as they require Z to be of size (20000,20000). Can anybody help? TIA

X = DAT(3,:);

Y = DAT(4,:);

Z = DAT(11,:);

[x,y] = meshgrid(X,Y);

surf(x,y,Z);

Upvotes: 2

Views: 10881

Answers (3)

letiantian
letiantian

Reputation: 437

http://www.mathworks.com/matlabcentral/newsreader/view_thread/311767 gives the code snippet may help you.

X=rand(1,30);
Y=rand(1,30);
Z=rand(1,30);

[XI YI ZI] = griddata(X,Y,Z,linspace(0,1),linspace(0,1)');

figure
subplot(1,2,1)
trisurf(delaunay(X,Y),X,Y,Z)
subplot(1,2,2);
surf(XI,YI,ZI)

Upvotes: 1

user85109
user85109

Reputation:

NO! plot3 does NOT require that of Z. If all you wish is to plot a point set, then plot3 does EXACTLY what you want.

plot3(X,Y,Z,'.')

The point is, there is NO need to use meshgrid for plot3. In fact, there is no need to use meshgrid as you have tried in order to use surf. (If you will be calling griddata, then meshgrid would be necessary, but for a SMALLER mesh.)

IF you need a surface plot, then you need to create a surface. If the points are scattered, then your basic options are tools like triscatteredinter, griddata, or gridfit, the last from the file exchange.

Upvotes: 1

ms611
ms611

Reputation: 101

Have you tried griddata or TriScatteredInterp to create an interpolated surface?

Upvotes: 2

Related Questions