MATLAB is a useful software tool for engineering and computational mathematics. It also plays a very important role in scientific and engineering plots. This project deals with 2D and 3D graphics plotting in MATLAB. It also explains the audio signal manipulations using plotting in MATLAB.
Familiarisation with basic MATLAB objects like vectors and matrices will help in understanding the subject better before delving into details. MATLAB has an excellent set of graphic tools. Plotting the given data set or the results of computation is possible using very few commands.
Plotting in MATLAB
2D plotting. To use the ‘plot’ function in MATLAB, you should first make sure that the matrices/vectors you are trying to use are of equal dimensions. Here we have taken a simple plotting example using the plot ( ) function as given below (its output plot is shown in Fig. 1):
You can also label the axes of the plot in Fig. 1 by using commands as given below. The plot becomes a time-distance plot as shown in Fig. 2.
Now, take an example of plotting a sine function using the following commands (its output is shown in Fig. 3):
Now, if you want to change the colour of line or pattern, use the command:
Here ‘r’ is the colour of the line. The ‘:’ (colon) is used for the line pattern and ‘4’ is the line width. Its output is as shown in Fig. 4. If you want to know more about the colours and patterns of line in MATLAB, type ‘help plot’ in command window and you will see the entire list.
To plot another graph with green colour on the same screen, we use ‘hold’ command as given below (its output is shown in Fig. 5):
The subplot ( ) function divides the current figure into rectangular panes that are numbered row-wise. An example for ‘subplot’ command is given below (its output is shown in Fig. 6):
An example of the polar command is given below (its output is shown in Fig. 7):
x = 0:0.2:5*pi;
y = x.^2;
Similarly, we also have other commands for 2D graphics like bar, stairs, loglog and semilogy.