# How to Plot a Line in 3D Matlab

Written by eric smith
• Share
• Tweet
• Share
• Pin
• Email

Many scientists and engineers use Matlab, a software application developed by Mathworks, to analyse small and large numerical data sets. They then visualise them onscreen using, for example, scatter, line and contour plots, with Matlab's extensive graphing functions. In addition to plotting numerical data, scientists and engineers use Matlab to plot equations. If you have a line described by three variables, you may need to plot it in three dimensions to help you understand the equation more thoroughly.

Skill level:
Moderately Easy

## Instructions

1. 1

Type "z = 0:(pi/100):(20*pi)" in the command window to generate a series of points along the z-axis.

2. 2

Type "x = cos(z)" to calculate the position of each z value on the x-axis.

3. 3

Type "y = sin(z)" to calculate the position of each z value on the y-axis.

4. 4

Type "plot 3(x,y,z)" to plot each of the points as a line -- a 3-D helix -- on a 3-D plot..

5. 5

Type "xlabel('cos(z)'), ylabel('sin(z)'), zlabel('z')" to label the axes.

6. 6

Type "grid on" to show grid lines.

#### Tips and warnings

• You can change the appearance of the line using the "linespec" line specification string syntax. Add the linespec string to the end of the plot 3 function arguments. For example, type "plot 3(x,y,z,'--or)" to plot a dashed line with circles at each point and colour both the line and markers red. Refer to the linespec documentation for all the different styles available.

### Don't Miss

• All types
• Articles
• Slideshows
• Videos
##### Sort:
• Most relevant
• Most popular
• Most recent