Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cell Arrays Definition Creating Cell Arrays Referencing Cell Arrays

Similar presentations


Presentation on theme: "Cell Arrays Definition Creating Cell Arrays Referencing Cell Arrays"— Presentation transcript:

1 Cell Arrays Definition Creating Cell Arrays Referencing Cell Arrays
Augmenting Cell Arrays Use of Cell Arrays

2 Data Types char (strings) double (float) or int8, int16… logical
Recall the workspace frame in MATLAB. Currently, 3 types of data have been seen. They are called: This lecture teaches a new data type called cell arrays char (strings) double (float) or int8, int16… logical

3 1. Cell Arrays - Definition
A data type that stores values of different types in indexed data containers called cells. A cell can hold any data type- string, integer, float, or even another cell array… Simply It is an ARRAY of CELLS

4 Quick Vocabulary Parentheses ( ) Brackets [ ] Braces { }

5 2. Creating Cell Arrays Cell arrays can be created by using the { } braces Separate cells in a row with commas (or spaces); separate rows with semi-colons. Likes arrays, cell arrays need to be rectangular Curly braces – not brackets!

6 2. Creating Cell Arrays, cont.
Visualize them using cellplot()! J o e

7 2. Creating Cell Arrays, cont.
Cell arrays can be of higher dimensions a 2 by 2 cell array

8 Question Is this cell array, A = {1:4; 2:3}, rectangular?
Answer: Yes, it is rectangular. Its size is 2 by 1.

9 3. Referencing Cell Arrays
Like with arrays, row and column indices are used Unlike arrays, there are 2 ways to reference a cell array, depending on the task: Get the entire cell as a whole, use (). - to move the container - to extract/copy/replace the container - to delete the container Get the content inside the cell, use {}. - To change/empty its content - To display/print its content

10 3. Referencing Cell Arrays
Parentheses property of the cell is shown, not content

11 3. Referencing Cell Arrays
A 1x1 Cell array containing a 1x4 array of doubles Curly Braces Content in the cell

12 3. Referencing Cell Arrays
>> x = cellmat(1,1); >> y = x+5; Undefined function 'plus' for input arguments of type 'cell'.

13 3. Referencing Cell Arrays
>> x = cellmat(1,1); >> y = x+5; ✗ >> x = cellmat{1,1}; >> y = x+5; ✔ y =

14 3. Referencing Cell Arrays
Cell indexing: ( ) Content indexing: { }

15 4. Cell Arrays – Augmenting
Add the string 'def'. ??

16 4. Cell Arrays – Augmenting
{ } are not used to augment. They are used to create new cell-arrays from scratch. - 'def' is added OUTSIDE of the cell array, C NOT what we wanted...

17 4. Cell Arrays – Augmenting
Instead, augment using square brackets

18 4. Cell Arrays – Augmenting
Add a row? Of course! Like with arrays, use ; to add a new row.

19 5. More Operations… Given C = {1, 2, 'Joe', 3.4, 'def'}
Delete the 5th cell Emptying contents of the 2nd cell Replace 3rd cell with the cell of content 'sam'; Change content of 1st cell to the number 8 Transpose, ', still works. C(5) = [] C{2} = [] C(3)= cellstr('sam') OR C{3} = 'sam' C{1}= 8

20 6. Why Cell Arrays? To store information of mixed data types
To store arrays of different sizes To store strings of different length Example: Names and grades? Daily temperature of 12 months. 28 days, 30 days or 31 days? Names of different length?


Download ppt "Cell Arrays Definition Creating Cell Arrays Referencing Cell Arrays"

Similar presentations


Ads by Google