make a 3d plot in matlab

To create a 3D plot in MATLAB, you can use the function plot3, meshgrid, or surf.

Here is an example using plot3 to generate a 3D line plot:

main.m
% Generate data
t = linspace(0,2*pi,100);
x = sin(t);
y = cos(t);
z = t;

% Plot the data in 3D
plot3(x,y,z)
xlabel('x')
ylabel('y')
zlabel('z')
title('3D Line Plot')
167 chars
13 lines

This will generate a 3D line plot with x and y coordinates represented on the x- and y-axes and z coordinates represented by the height of each point.

Here is another example using meshgrid and surf to generate a 3D surface plot:

main.m
% Define the x and y ranges
x = linspace(-3,3,100);
y = linspace(-3,3,100);

% Create a meshgrid from the x and y ranges
[X,Y] = meshgrid(x,y);

% Define a function to plot in 3D
f = @(x,y) sin(sqrt(x.^2 + y.^2));

% Evaluate the function at each point of the meshgrid
Z = f(X,Y);

% Plot the surface
surf(X,Y,Z)
xlabel('x')
ylabel('y')
zlabel('z')
title('3D Surface Plot')
374 chars
20 lines

This will generate a 3D surface plot using surf, with x and y coordinates represented on the x- and y-axes and z coordinates represented by the height of each point.

gistlibby LogSnag