Professional Documents
Culture Documents
Expt 1a. Getting Started Wih Matlab and Octave
Expt 1a. Getting Started Wih Matlab and Octave
Name:
S e c ti o n :
Date Assigned:
D a t e S u b m i tt e d :
EXPERIMENT 1
G e tti n g S t a r t e d w i t h M a t l a b / O c t a v e
Matlab and GNU Octave are mathematics-oriented software with built-in plotting and
visualization tools. GNU Octave, which you will be using for this course, is a free software that runs on
GNU/Linux, macOS, BSD, and Windows. Its syntax is largely compatible with Matlab. GNU Octave will
simply be referred to as Octave in this laboratory manual.
Octave can be downloaded from https://www.gnu.org/software/octave. Below is the step-by-
step installation procedure indicated by the orange arrow symbol.
Select the appropriate system type applicable to your PC, for example 64-bit operating system.
Wait until the file is saved and then proceed with the installation.
GNU Octave comes with a large set of general-purpose functions that is available without any
packages installed. The list can be seen from https://octave.sourceforge.io/octave/index.html .
Octave Forge is a central location for development of packages for GNU Octave which is similar
to Matlab's toolboxes. To list the available package, use the pkg command from the Octave prompt by
typing:
>> pkg list
To load a package, choose the package name from the list and type
>> pkg load package_name
Practice Exercises:
I. PLOT
The plot command is used to create two-dimensional plot.
Syntax: plot(x,y)
Where x and y are vectors with the same number of elements.
Do this:
wt = 0:0.5:10;
y1 = 2*cos(wt); % y1 is computing the cosine of all the values in wt and
%multiplied each by 2. Since cosine is used, the maximum
%amplitudes of y1 are ±2.
figure 1,plot(y1); %the values on the x-axis are the matrix indices 1,2,3,…,length(y1)
figure 2, plot(wt,y1); %the values on the x-axis are the values of wt.
IV. LEGEND
syntax: legend (STR1, STR2, ...)
This is demonstrated on the code above. The str1, str2, must be in the order as how you
plotted the waveforms. Referring to the plot command above, the order is y1,y2,y3.
V. SUBPLOT
syntax: subplot(m,n,p)
m-number or rows, n-number of columns, p-position. Only the p value chages.
The figure below (2x3) has 2 rows, 3 columns, and the position numbers are as
shown. The position number is from left to right starting from top .
The activities above serve as a practice on how to use the basic commands in Matlab, which can
also be done in Octave. When you are in Octave, you may be encountering an error like the one shown
below
Simply load the particular package that you need, in this case, the signal package. You may do it on the
command window or within the editor.