Matlab Introduction: Dr. Antonio A. Trani Professor Dept. of Civil and Environmental Engineering
Matlab Introduction: Dr. Antonio A. Trani Professor Dept. of Civil and Environmental Engineering
• Workspace Window
- to view variable definitions and variable memory
allocations
• M-File Editor/Debugger Window
- to write M-files (includes color-coded syntax features)
- to debug M-files interactively (break points)
• MATLAB Path Window
- to add and delete folders to the MATLAB path
• Command History Window
- displays all commands issued in MATLAB since the last
session (good for learning and verification)
Workspace
Window
Current
Folder
Command
Window
Command
History
MATLAB Workspace
Computer RAM
MATLAB Workspace
Computer RAM
Swap Space Memory
MATLAB
Application
Another
Application
Mode Remarks
Command line • Interactive mode
• Good for quick computations or
changes
M-files (script files) • Semi-interactive mode
• Good to prototype small to com-
plex models
• Used most of the time
• Platform independent
Executable MEX files • Require a C/C++ compiler
• Fastest to execute
• Platform specific (target specific)
cd changes directory
copyfile copy a file
dir lists files in current directory
pwd displays the working directory and its full path
delete delete a file
mkdir make a directory
dos execute DOS command and return result
unix execute UNIX command and return result
140
120
100
No. of Trials
80
60
TextEnd
40
20
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
RN
1
RN and RU
TextEnd
-1
-2
-3
-4
0 100 200 300 400 500 600 700 800 900 1000
Index i
0 4 7 11
1325
2224
3426
4 2 8 10
.......
Import
Command
format long
fid = fopen ('ohare_schedule',’rt’) % ‘rt’ = read text file
y = fscanf(fid, '%g', [4,inf]); % reads in 4 columns
y = y';
fclose(fid);
• textscan reads the row data using ‘%s %s’ two string
variables and two ‘%f %f’ numerical variables (f stands
for floating point)
fclose(fid);
Bridge Name
Country
Year
Completed
Length (m)
• readData{1}(3,1)
references the third row
element of the cell array
• readData{1}(3:5,1)
references the third, fourth
and fifth row elements of
the cell array
• readData{3}(1:5,1)
references the first five row
elements of the third
column of the cell array
Bridges_of_the_world_short.xls
Virginia Tech (copyright A.A. Trani) 56m
What Happens after Executing the One
Line Script?
• Three arrays are created using the previous script
• ‘num’ is a standard
numeric array as
shown
• Elements of ‘num”
can be referenced
in the usual
(row,column)
format
• num(2,2)=8230
• Elements of ‘txt”
can be referenced
using the cell array
nomenclature
cell{i}(row,column)
• txt{1,2}=Country
• readData{3}(1:5,1)
• txt{1}(1,2)=N
• [num,txt,raw] = xlsread
('bridges_of_the_world_short.xls','Bridge data
(A2:D24)');
Note that a specific format with four digits has been used
in this example.