Professional Documents
Culture Documents
1. MATLAB Environment
Basically this environment consists of four main panels which are menu pane , current
folder , command window and workspace respectively. Current folder
shows which folder you are working on. It is important to right click on the folder and
select add to path current folder and sub-folders. Otherwise MATLAB can not find the .m
files or the data you want to work. Command window is the main calculation
environment. In the upcoming sections you will be familiar with the editor where your
scripts (.m files) works. Lastly the workspace shows the variables which can be the data
you’ve uploaded and/or the results of your calculations.
1.1. Scalars
>> 24 + 12
MATLAB will display the result as
ans =
36
and stores the result in workspace as ans which is 1×1 matrix. Because MATLAB’s logic is
working with matrices. Once you store the result as ans, you can numerate any other
calculations with using ans as
>> ans /4
ans =
The problem here is the ans stored in workspace changes if you continue to numerate
calculations. Every answer overwrites on ans. If you want to store results to use them in
future calculations you have to give them names.
>> y = 4
y=
>> x = 52
x=
52
>> X = 43
X=
43
>> x = 42
x=
42
You gave names to your variables and temporarily store them in workspace. There is no
necessity to show them answers in command window. This can be solved with using
semicolon
>> x = 42
x=
42
>> x = 42;
or
>> a = 4, b = 72;
a=
Once you gave names to variables you can call back them for calculations for example
c = b/a*x
c=
756
>> pi
ans =
3.1416
ans =
3.141592653589793
ans =
3.1416
Single variable called as array and if your array is a one-dimensional data set then it is
called as vector. Vectors are also matrices for example
4 45 17 14
Brackets [] are used to write the elements of matrices, arrays or vectors. Semicolons are
used to separate each matrix rows from each other
B=
12 14 15
22 23 25
32 33 34
>>B'
ans =
12 22 32
14 23 33
15 25 34
>>B(1,3)
ans =
15
which is as you may remember from your calculus courses 1 refers for the first column
and 3 refers for the third row.
>>B'
ans =
12 22 32
14 23 33
15 25 34
Assignment 1. Form a matrix which has 14 columns and 72 rows which consists of zeros.
Save your matrix as an .m file (script). Matrix and script should have their own names.
Give what you want. Keep that in mind that variable should be stored on workspace,
there shouldn’t be any answers displayed in command window. Upload the assignment
to the relevant assignment box in moodle. Deadline is 3rd March Wednesday, 09.59 am.