Вы находитесь на странице: 1из 8

INSTITUTE OF DEPARTMENT OF

TECHNOLOGY OF CAMBODIA ELECTRICAL AND ENERGY ENGINEERING

Group: I3 A2

Report
Basic Operation in MATLAB

Electr. lab Part 4

Lecturer: Mr. CHHOR Sopheaktra

Student:KHOV Bunly (e20160263)

Academic Year: 2018-2019


Table of Contents
I.Objective ................................................................................................................................................... 1
II.Processive................................................................................................................................................ 1
1.Command window ............................................................................................................................. 1
2.A script ................................................................................................................................................. 1
III.Result....................................................................................................................................................... 3
1.Command Window............................................................................................................................. 3
2.Create a script ..................................................................................................................................... 4
IV.Discussion .............................................................................................................................................. 5
V.Conclusion ............................................................................................................................................... 6
Practice 1 Basic Operation in Matlab 2 hours

I. Objective
 Understanding the characteristic of the Basic Operation in Matlab
 Scalar, Array, and Matrix
 Command window, Script, Workspace and Current folder
 Input and Output
o The command ‘Input’
o The command ‘Displays’
o The command ‘Plot’

II. Processive
 A scalar is a value in a single element. Mostly, the scalar can be referred to one-
dimension array or 1-by-1 matrix
 Array is the most fundamental data type in MATLAB. It is a collection of several
value of the same type. i.e. string array, integer array…etc. Basically, array is a vector
of the same data set.
 Matrix is the array with more than one dimension.

1. Command window
Command window is place that you can put your individual statement (code)

for MATLAB to execute.

Create an array that consists of 8 elements: A=1 2 5 8 9 0 4 10

To create this array, you go command window and typing A= [1 2 5 8 9 0 4 10].

Note: between each value there is a space.


1235
Create a 2-by-2 matrix A=[ ]
2680
To create this matrix, you go command window and typing A= [1 2 3 5;2 6 8 0].

Note: between each value there is a space and there is a semicolon (‘;’) to

separate each row.

2. A script
A script is a file with a .m extension (file type i.e. square .m) that contains multiple
sequential lines of MATLAB commands and function calls. You can run a script by typing
its name at the command line.

1
o Create a script that allow you to input two difference types of variable (array,
scalar or matrix) and display the value of those variable in the commend
window.

clear all;

clc;

First_data=input('Set first data=');

Second_data=input('Set second data=');

display(First_data);

display(Second_data);

o Create a script that allow you to show any graph of sinusoidal wave form
y=A*sin((2*pi*f*Time)+phi).

clear all;

clc;

A=input('Set Amplitude [V] =');

f=input('Set frequency [Hz] =');

T_start=input('Set starting time [s] =');

T_stop=input('Set stopping time [s]=');

T_sampling=input('Set sampling time [s] =');

phi=input('Set phase of signal [deg] =');

Time=T_start:T_sampling:T_stop;

y=A*sin((2*pi*f*Time)+phi);

plot(Time,y);

title('SinGraph');

xlabel('Time [s]');

ylabel('Amplitude');

xlim([T_start T_stop]);

grid minor;

2
III. Result
1. Command Window

Figure 1: Array in command window 8 element

Figure 2: Create a 2-by-2 matrix

3
2. Create a script

Figure 3: Create script with command input and display

Figure 4: Create script to show graph of y=A*sin((2*pi*f*time)+phi)

4
Figure 5: The graph of y=A*sin((2*pi*f*time)+phi)

IV. Discussion
1. For figure 1: A array in command window 8 element. To create this array, you go
command window and typing A= [1 2 5 8 9 0 4 10] and then your press’ ENTER’.
2. For figure 2: Create a 2-by-2 matrix. To create this matrix, you go command window and
typing A= [1 2 3 5;2 6 8 0] and then you press ‘ENTER’.
3. For figure 3: Create a script that allow you to input two difference types of variable

(array, scalar or matrix) and display the value of those variable in the commend window.

clear all; % Clear every thing

clc; % Clear command window

First_data=input('Set first data='); % Create first input

Second_data=input('Set second data='); % Create second input

display(First_data); % Display first data

display(Second_data); % Display second data and then press ’RUN’ .

4. For figure 4: Create a script that allow you to show any graph of sinusoidal wave form
y=A*sin((2*pi*f*Time)+phi) and display the value of those variable in the commend
window.

clear all; % Clear every thing

clc; % Clear command window

A=input('Set Amplitude [V] ='); % Input amplitude

5
f=input('Set frequency [Hz] =');% Input frequency

T_start=input('Set starting time [s] =');% Input starting time

T_stop=input('Set stopping time [s]=');% Input stopping time

T_sampling=input('Set sampling time [s] =');% Input sampling time

phi=input('Set phase of signal [deg] =');% Input phase of signal


Time=T_start:T_sampling:T_stop;% creat time frame

y=A*sin((2*pi*f*Time)+phi);% Calculate output

plot(Time,y);% Display the graph at command window

title('SinGraph');% set title of the graph

xlabel('Time [s]');% set label for x-axis

ylabel('Amplitude');% set label for y-axis

xlim([T_start T_stop]);% set limitation of x-axis

grid minor;% open the sall grid and then press ’RUN’ .

V. Conclusion
1. Command window is place that you can put your individual statement (code)

for MATLAB to execute.

2. To create this script, you must create a script as show in the previous part by using
file name as “SinGraph”. Note: you can use any file name as you want. Then, you
write the code to the script as below. After running the script, you can set the value
of the input at the command window. Note: if you satisfy with your first data, you
must click “ENTER” in order to set the second value.

Вам также может понравиться