Lec 4
Lec 4
➢ If you include more than one function per file, only the
first function is accessible in other scripts
2
Outline
3
Statistics
• Built-in functions
➢ mean, median, mode
» y=randn(1,1000)
» y2=y*5+8
➢ increases std to 5 and makes the mean 8
6
Exercise: Probability
7
Outline
8
Advanced Data Structures
9
Cells: organization
L e o []
• One cell can contain people's names, ages, and the ages of
their children
• To do the same with matrices, you would need 3 variables
and padding 10
Cells: initialization
11
Exercise: Cells
12
Structs
• To add fields
» s.name = ‘Leo';
» s.age = 18;
» s.childAge = [];
➢ Fields can be anything: matrix, cell, even struct
➢ Useful for keeping variables together
15
Exercise: Structs
16
Outline
17
Handles
21
Importing Data
» x=a.data;
» names=a.colheaders; 22
Importing Data
23
Writing Excel Files
• You can also write a cell array if you have mixed data:
» C={'hello','goodbye';10,-2;-3,4};
» xlswrite('randomNumbers',C,'mixedData');
26
Lecture 5
28
End of Lecture 4
29