Benjamin Alonso Tan
Benjamin Alonso Tan

Reputation: 33

Plot 3d surface plot in matlab/freemat

I would like to ask about 3d surface plotting. As I am new to it, I was just trying out. Basically, I have 3 parameters, x, y ,z which I have the values from experimental datas and I would like to plot them out. As such, i tried,

x= [6 7 8 9 10 11 12 1]
x =
  6  7  8  9 10 11 12  1
--> y=[2 3 4 5 6 1 6 8]
y =
 2 3 4 5 6 1 6 8
--> z= [3 4 5 6 7 8 9 10]
z =
  3  4  5  6  7  8  9 10
meshgrid(x,y,z)
surf(x,y,z)

The plot window did come out but there was no graph. Is my method wrong?

Thanks!

Upvotes: 1

Views: 1775

Answers (2)

James Archer
James Archer

Reputation: 421

This is how I would plot a surface :

%define the data 
x=[6 7 8 9 10 11 12 1 6 7 8 9 10 11 12 1];
y=[2 3 4 5 6 1 6 8 2 3 4 5 6 1 6 8];
z=[3 4 5 6 7 8 9 10 3 4 5 6 7 8 9 10];

%Create 3D surface
[X,Y]=meshgrid(x,y);
Z=griddata(x,y,z,X,Y);

%Plot the surface
surface(X,Y,Z);
shading interp %makes it look sexy
%xlim([])
%ylim([])

Sometimes I use axis limets to make the plot look nicer (eliminates the unneeded white area's); for this set of data I could use xlim([6 11]) and ylim([2 6]).

Upvotes: 0

adalca
adalca

Reputation: 145

It sounds like you need to start with plot3, as you're just describing a set of points in 3D, rather than points on a mesh or surface. See if that does what you want.

x = [6 7 8 9 10 11 12 1];
y = [2 3 4 5 6 1 6 8];
z = [3 4 5 6 7 8 9 10];
plot3(x, y, z, '.');

Upvotes: 1

Related Questions