Tp1-Matlab Command Window
Tp1-Matlab Command Window
Faculty of Technology
TP1- Introduction to Matlab ING-ST 2nd year
EBT Department 1 session A.Y:2023/2024
_______________________________________________________________________________________________________________________________
0- Introduction :
The name MATLAB® stands for MATrix LABoratory. Is a high-performance modern matrix-based
language for technical computing and express computational mathematics. It integrates computation,
visualization, and programming environments and built-in graphics make it easy to visualize and gain
insights from data. These factors make MATLAB an excellent tool for teaching and research.
Official site : https://www.mathworks.com/
1- Matlab desktop (Interface- version 2013a ):
When you start MATLAB, the default MATLAB desktop appears.
3 4
2
2- Working mode :
Matlab propose 2 working modes : interactive mode (command window) and programming mode (script)
1
2.1 interactive Mode (command window):
just enter the command or mathematical expression at the prompt (>>) in command window and Matlab
will response;
a- Using variables :
A variable is only a computer memory location identified by a name and it has a type (real, integer,
complex, characters string).
To see all variables used in Matlab session, do one of the following method:
i. Using workspace panel (HOME/layout/workspace)
ii. Using command window with whos command
- To save all variables in file filename.mat in current folder use this command : save('filename.mat' )
- To load the variables from file named filename.mat use this command : load('filename.mat' )
- To delete a specific variable use this command: clear x
- To delete all variables use this command: clear all
b- Variables types:
In Matlab, the basic element of variables is a Matrix. Each element of this matrix has a type among the
following basic types: an integer , a double, a complex, a character string, a logical type (Boolean).
2
n.b. : Don’t use these names as variables names : pi(pi value =3.14), i, j (complex number i2 = j2 =-1), eps
(error precision)
Example : c- Some useful commands:
>>a= 2 % a is an integer but it’s clc : clear console
coded as double (Real number). who : Displays variables list
>>b = 1.3 % b is double.
whos : Displays detailed variables list (size, type).
>>c = 3+i % c is complex number.
>>d = 'bonjour’ % d is characters string. clear x : delete variable x.
>>e= true % or e = logical(1) , e is boolean clear all : Delete all variables.
Task 1:
Let giving this set of matlab commands, complete this table:
Command Effect
>> x = 2 Creates variable named x with value 2
>> X = x*2 ………………………………………………….
>> y = sqrt(X) ………………………………………………….
>> % Y = y * y ………………………………………………….
>> Y ………………………………………………….
>> clc ………………………………………………….
>> save('myvars.mat') …………………………………………………..
>> clear all ………………………………………………….
>> z=x*4 ………………………………………………….
>> load('myvars.mat') ………………………………………………….
>> whos ………………………………………………….
>> x ………………………………………………….
>> z=x*4 ………………………………………………….
d- Arrays in Matlab :
An array is a collection of elements with the same data type. In MATLAB, the most commonly used types
of arrays are 1D arrays (vectors), and 2D arrays(matrices)
Task 2:
Execute the following MATLAB commands manually and check the results in the command window:
Command Effect
>> M1 = [4 5 2 ; 6 -4 3] ………………………………………………….