Basic Plotting In MATLAB



Enjoyed our previous posts??
Now Do read us further for something like an Introduction about Plotting graphs in MATLAB
Well now, proceeding towards  the next step by graphically plotting your calculations and results. MATLAB  makes it easy for you to do so by just typing a few commands!! So what are you waiting for ?? … Let’s get started!!

Suppose you have a set of points to be plotted, for this you have to create two arrays (row or column vectors) namely X and Y (for example).

X  and Y contains the set of points corresponding to the X-axis and Y-axis respectively.

The command used fo this is "plot(x,y)"

Example:- You have to plot the following points (1,2),(2,3),(3,4),(4,5).

Then just do type it like this:-
>> X=[1 2 3 4] ;
>> Y=[2 3 4 5];
>> plot(X,Y)

Now See what plot you have obtained from that:-

MATLAB Plot of Graph
MATLAB Plot of Graph
 If you have obtained something like above, I must congratulate you that you did it. You have plotted a graph in the MATLAB using the X & Y axis value.


Let’s try to plot a simple function sin(x) in the interval [0,2π]. To get this done create a vector having the range of the values to be plotted .
Example:-

X varying from 0 to 2 π in the intervals of π/50.
>>X=0:pi/100:2 *π;
>>Y=sin(X);
>>plot(X,Y)
Lets See results!!
MATLAB Sine Plot Graph
MATLAB Sine Plot Graph

Now that are done with the basics of plotting we will move further in plotting. For that you need to hold on and be eager to read the next post (coming soon)!!
Hope you learnt a new thing from this…
Please drop on your comments below.

Pulkit Khandelwal,
VIT University ,Vellore.