Chapter 2: Plotting in MATLAB
Before we plot a graph on matlab we should specify what will be our x axis and our y axis. For instance, we could let x be the independent variable
and y is a function of x.
If we want to plot a cosine
function we could type:
>> t = 0:0.001:5; %this means, the first number 0
is the initial value and 5 is the last value,
%the
0.001 is the increment of the cosine function,
%NOTE:
make sure to put a semi-colon after every syntax
>>y =
cos(t-0.25); %our function;
>>plot(t,y,’r’) %plot
syntax; ‘r’ means the color of the line is red
You should have a graph like this:
We could also put title, label on our
graph:
>>title(‘Cosine plot’)
>>xlabel(‘time’)
>>ylabel(‘Amplitude’)
That’s it for plotting graph..you could
place two or more graphs in one figure.
Note: Try exploring the syntax ‘subplot’. Without the quotes. You could also try changing the values of t, comment your exploration here. It is much appreciated. Thanks! Up next..
Simulink Basics
0 comments