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):

[stextbox id=”grey”]x = [3 9 27];

t = [1 2 3];

plot (t,x);[/stextbox]

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.

[stextbox id=”grey”]xlabel(â€˜Time(s)â€™); % label

for x axis

ylabel(â€˜Distance(m)â€™); %

label for y axis

title(â€˜Plot of Distance over

Timeâ€™); % giving the title

legend(â€˜Trial 1â€™);

legend(â€˜Locationâ€™,

â€™Northwestâ€™); % move legend

to desired location[/stextbox]

Now, take an example of plotting a sine function using the following commands (its output is shown in Fig. 3):

[stextbox id=”grey”]x = 0: pi/100: pi*2;

y = sin(x);

plot(x, y);[/stextbox]

Now, if you want to change the colour of line or pattern, use the command:

[stextbox id=”grey”]plot(x,y,â€™r:â€™,â€™Linewidthâ€™,4);[/stextbox]

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):

[stextbox id=”grey”]x = 0: pi/100: pi*2;

y = sin(x);

z = cos(x);

plot(x, y, â€˜râ€™);

hold on

plot(x, z, â€˜gâ€™);[/stextbox]

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):

[stextbox id=”grey”]

x = 0: pi/100: pi*2;

y = sin(x);

z = cos(x);

t = exp(-x);

u = (x.^3);

subplot(2,2,1);

plot(x,y);

subplot(2,2,2);

plot(x,z);

subplot(2,2,3);

plot(x,t);

subplot(2,2,4);

plot(x,u);Â [/stextbox]

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;

polar(x, y,â€™*â€™);

Similarly, we also have other commands for 2D graphics like bar, stairs, loglog and semilogy.

i need a source code ??

The source code is present within the article.

I can’t find source code in the article. please help me. where it is?

The source code is present at the 3rd page of the article.