plot 3d in matlab

To plot 3D charts in MATLAB, we can use the following functions:

  1. plot3: This function is used for plotting 3D lines or point-by-point.

  2. meshgrid: This function creates a matrix of x, y, and z coordinates for a 3D plot.

  3. surf: This function is used for 3D surface plots.

  4. scatter3: This function is used to plot 3D scatter plots.

Here is an example code to plot a 3D surface:

main.m
% Creating data
[X, Y] = meshgrid(-2:.2:2);
Z = X .* exp(-X.^2 - Y.^2);

% Plotting data
figure
surf(X,Y,Z)
108 chars
8 lines

The above code creates a surface with x and y between -2 and 2 with increment of 0.2, and z is given by the function Z = X .* exp(-X.^2 - Y.^2). The surface is then plotted using the surf function.

Hope it helps!

related categories

gistlibby LogSnag