An interactive introduction to MATLAB

(Jeff_L) #1

26 plotting


ï (^1000102030405060708090100)
ï 50
0
50
100
150
200
250
300
350
xïdata

data
Basic curveïfitting
Original data
Line of best fit
Figure 7: Usingpolyfitandpolyvalfor curve-fitting
Comments:



  • 'r+'plots thexandydata using red crosses.

  • You can insert a legend from the Command Window using thelegend
    command, and specifying the text in the legend using strings.


2.3 3 dplotting using plot3 and surf


MATLABis hugely powerful and versatile at visualising data in 3d. There
are a number of built-in functions for producing different types of 3dplots e. g.
points, lines, surfaces and volumes.
The 2dplotfunction becomesplot3(x,y,z)for plotting points and lines
in 3dspace. Listing 2.5 and Figure 8 demonstrate usingplot3to plot the
points on a helix in 3dspace.
Listing 2.5: Usingplot3to plot points on a helix
1 >> t = 0:pi/50:10*pi;
2 >> plot3(sin(t),cos(t),t,'r.'), grid on, ...
3 xlabel('x'), ylabel('y'), zlabel('z'), title('3D helix')
Free download pdf