01:198:107 Lecture Notes - Lecture 19: Bracket, Delimiter, Row And Column Vectors

98 views3 pages
CS 107: Lecture 19: Cell arrays and text file I/O
What is a cell array?
A cell array is a collection of containers called cells in which you can store
different types of data, like a matrix, strings, vectors, numbers
Creating a cell array
A(1,1)={[1 4 3; 0 5 8; 7 2 9]}
A(1,2)={‘Anne Smith’};
A(2,1)={3+7i};
Matlab will display the sizes of sub-structures or the substructure itself
Nesting one cell array in another
header={‘Name’, ‘Age’, ‘Pulse/Temp/BP’};
records(1,:)={‘Kelly’,49,{58,98.3,[103,72]}};
Header,records
header=’Name’ ‘Age’ ‘Pulse/Temp/BP’
records=’Kelly’ [49] {1x3 cell}
Building a cell array in steps
vitalsigns={60, 98.4, [105,75]};
records(1,:)={‘Kelly’, 49, vitalsigns}
records=’Kelly’ [49] {1x3 cell}
Alternative assignment syntax
A(1,1)={[1 4 3; 0 5 8; 7 2 9]);
A(1,2)={‘Anne Smith’};
Or
A{1,1}=[1 4 3; 0 5 8; 7 2 9];
A{1,2}=’Anne Smith’;
Concatenating cell arrays
There are two ways that you can create a new cell array from existing cell
arrays
C={C1,C2} - concatenate entire cell arrays to individual cells of the
new array using curly brace {} operator
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

Document Summary

Cs 107: lecture 19: cell arrays and text file i/o. A cell array is a collection of containers called cells in which you can store different types of data, like a matrix, strings, vectors, numbers. A(1,1)={[1 4 3; 0 5 8; 7 2 9]} Matlab will display the sizes of sub-structures or the substructure itself. A(1,1)={[1 4 3; 0 5 8; 7 2 9]); A{1,1}=[1 4 3; 0 5 8; 7 2 9]; There are two ways that you can create a new cell array from existing cell arrays. C={c1,c2} - concatenate entire cell arrays to individual cells of the new array using curly brace {} operator. C=[c1 c2] - concatenate the contents of the cells into a new array using the bracket [] operator. C2={ mar" apr" may"; 31" 2" 10"; . Reading a text file into a cell array.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents