Experiment 1 Avenido CP Final
Experiment 1 Avenido CP Final
I. INTRODUCTION
The tutorial used in the experiment is intended for beginners
in MATLAB. Various topics are discussed, though in an
introductory manner. The discussion on MATLAB functions is
strictly limited to what is only essential for electrical
engineering students for an initial hands-on experience. The Fig. 2 Assigning variable names
tutorial also requires that the discussion for a specific topic to be
dispersed out on the whole material and not just focused on one Variables cannot be defined with the same names as
case. The intention is to explain only what is significant as the MATLAB keywords, such as if or end.
students read and implement the discussed MATLAB
To remove a certain variable from the workspace, the
commands.
command is clear variableName. The command clear removes
II. METHODOLOGY all the variables in the workspace. The command clc clears all
the text from the Command Window, resulting in a clear
A. Getting Started screen.
The MATLAB prompt (>>) is where formulas, commands,
or functions are typed next to. Pressing the Enter key processes The MATLAB variables are case sensitive, i.e. the variable
the command. A simple mathematical calculation can be ‘J’ is different from ‘j’.
performed by typing it at the prompt. MATLAB has integrated variables like pi (π), i and j (the
imaginary operator or -1), and eps (the smallest difference
between two numbers as represented in MATLAB). The user
should be careful not to use integrated variables or keywords as
variable names in the workspace.
Pressing the arrow up (↑) views the previous lines that have
been entered. This is similar to the copy and paste method
where the user does not need to retype the lines.
Multiple commands can be entered on a single line by
separating them with commas.
Anytime MATLAB encounters a percent sign (%), it treats
the rest of the line as a comment. Comments do not affect the
code itself.
Fig. 5 Using help command to view the list of elementary math functions
Fig. 10 Listing numbers 1 to 10 using colon operator Fig. 13 Plot of a sine wave with lesser increment
The default increment is 1 when listing a range of numbers Typing x = 0:0.02:1, y = sin(2*pi*1*x), plot(x,y) results in
using the colon operator. the figure above. The sine wave looks smoother because of the
0.02 increment. To obtain a finer plot, use a smaller increment
value.
C. Plots
The function plot(x, y) is used to create plots in MATLAB. Fig. 14 Red-colored plot of a sine wave
Entering the function causes a separate figure window to appear. The color of the plot can also be changed. To obtain a red-
Increments can also be specified when creating plots. Finer plots colored curve, type figure, plot(x,y,'r'). The ‘r’ applies color
can be achieved by decreasing the increment value. red to the plot.
Fig. 15 Customization of the plot of a sine wave Fig. 18 Customization of the plot of a sine wave
Typing figure(1), grid, xlabel('Time, sec'), ylabel('Signal Typing figure, stem(x,y) results in the figure above. In
value'), title('Sine Wave') results in the figure above. The plot plotting discrete-time signals, a 'lollipop' or stem plot is often
looks more detailed with the addition of gridlines, x-axes and y- desired. The command stem(x,y) plots the data sequence y at
axes labels, and title. the values specified in x.
III. RESULTS AND DISCUSSION
A. Getting Started
Pressing the up arrow key (↑) allows the user to review past
commands and/or functions. This is helpful if the user needs to
Fig. 17 Customization of the plot of a sine wave alter parts of the code containing an error. It also serves like a
copy and paste function where the user can edit the command
Typing figure, plot(x,y,'g',x,y,'ko') results in the figure without retyping the whole line.
above. The ‘g’ applies color green and ‘ko’ applies o-shaped
markers to the plot.
B. Matrices
C. Plots
Under the Tools menu, there is Edit Plot. The user can edit The axis function allows the user to display two cycles of
the plot by adding gridlines and changing the curve color, line the cosine wave instead of three. By using the format
style, line width, marker type, and marker size. Under Edit axis([XMIN XMAX YMIN YMAX]), the scaling for the x-
menu, the user can choose to copy the figure and paste it to a and y-axes can be set. Typing axis ([0 1 -1 1]) in the command
Word document. window results in the figure above. The XMAX is changed from
1.5 to 1, creating a two-cycle cosine wave.
IV. CONCLUSION
Familiarizing MATLAB is very essential for aspiring
engineers. As an electrical engineering student, having a solid
foundation in this programming environment is necessary when
dealing with circuit analysis, differential equations, and
advanced engineering mathematics. The tutorial was able to
clearly deliver the topics in a pace similar to the user’s learning
ability. It explained the subtleties in the software’s adopted
syntax and their distinct effects to the output. MATLAB has a
wide range of help commands making it appealing to
programming amateurs. MATLAB encourages creative
Fig.25 Plot of a cosine wave with 3 cycles at 2 Hz thinking in solving various problems with the help of the
numerous tools at its disposal.
Typing x = 0:0.02:1.5, y = cos(2*pi*2*x), figure, plot(x,y),
grid, xlabel(‘Time, sec’), ylabel(‘Signal value’), title(‘Cosine REFERENCES
wave’) in the command window results in the figure above. [1] Mathworks.com. (2019). Getting Started with MATLAB. [online]
𝑦(𝑡) = 𝐴𝑐𝑜𝑠(2𝜋𝑓𝑡 + 𝜙) Available at: https://www.mathworks.com/help/matlab/getting-
started-with-matlab.html [Accessed 5 Sep. 2019].
Eq. 1 Cosine wave equation
[2] Cyclismo.org. (2019). Introduction to Vectors in Matlab — Matlab
Equation 1 shows the most basic form of cosine wave as a Tutorial 3.0 documentation. [online] Available at:
https://www.cyclismo.org/tutorial/matlab/vector.html#basic-
function of time where: A is amplitude, f is frequency, 2πf is operations-on-vectors [Accessed 5 Sep. 2019].
angular frequency, and ϕ is phase angle. In the y equation found
in Figure 25, time x is multiplied by 2 in order to achieve a
frequency of 2 Hz.