state->city. Key methods for manipulating character strings, cell arrays and structures were also presented.">state->city. Key methods for manipulating character strings, cell arrays and structures were also presented.">
Cell Arrays and Structures: Learning Objectives Topics
Cell Arrays and Structures: Learning Objectives Topics
Cell Arrays and Structures: Learning Objectives Topics
Learning
Objectives
Learn about
characters, cell
arrays &
structures
Topics
Data Types
Character Strings
Cell Arrays
Structures
Summary
Examples
Gradebooks
Hierarchical geographic data
32
% What do you observe?
Learn?
Example
u = double(T)
char(u)
Exercise
a = double('a')
char(a)
u = T(16:24)
u = T(24:-1:16)
u = T(16:24)
v = 'I can''t find the manual! % Note quote in string
u ='If a woodchuck could chuck wood,';
v = 'how much wood could a woodchuck chuck?';
w = [u,v] % string concatenation in Matlab
disp(u)
% works just like for arrays
Lessons?
Exercise
lawyers = char('Cochran','Shapiro','Clark','Darden');
lawyers(3,:)
Lesson?
Exercise
help char
help str2mat
help strvcat
Lesson?
Lesson?
>> u = double (t)
>> char(u)
Lesson?
>>u = t(16:24)
>>u = t(24:-1:16)
>>u = t(16:24)
Lesson?
Page 129-131
third
third (1,1), third {1,1}
third (2,1), third {2,1}
third (3,1), third {3,1}
size(C)
C(2:3)
C([4,3,2,1])
[a,b,c,d] = deal(C{:})
Lessons?
Lesson?
A = cell(1,3) % Note 1 x 3
A = {'My' , 'name', 'is' , Burdell'} %
A = {'My'; 'name'; 'is' ; Burdell'}
Lessons?
Exercise Important
help lists
Note 1 x 4
Lesson?
Exercise
help cell
help cellstr
help celldisp
B = cell(2,4)
B = {'My', 'name', 'is', Burdell; 10, 20, 30, 40}
celldisp(B)
Lesson?
Creating a Structure
Lets create a simple structure:
person.firstname = George;
person.lastname = Burdell;
person.address1 = 803 Tech Parkway;
person.city = Atlanta;
person.state = GA;
person.zip = 30332-0001;
text1
Hello
numb1
[1 2 3 4]
text2
AE6382
Fall 2004
numb2
5 6
7 8
mystruc
More on Structures
A structure can have a field that is a structure itself.
A structure array is that which contains more than one
record for each field name.
As the structure array is expanded (more records are
created), all unassigned fields are filled with an empty
matrix.
All structures have the same number of fields and
elements in each field.
NOTE: There
are other
spaces to fill,
but we havent
assigned any
values to
these fields,
so they remain
as an empty
matrix.
first
Joe
Anna
Jerry
last
Smith
Lee
[]
score
82.39
94.50
[]
grade
[]
[]
name
student
Structure Resources
Structures are explained in the Matlab online
documents.
You can find tutorials on the web:
http://www.mathworks.com/
Summary
Learning
Matlab can store
and manipulate
much more than
simply numbers
Action Items
Review the lecture
Review the material on the websites