high level in 2 parts n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
High Level in 2 parts PowerPoint Presentation
Download Presentation
High Level in 2 parts

Loading in 2 Seconds...

play fullscreen
1 / 28

High Level in 2 parts - PowerPoint PPT Presentation


  • 96 Views
  • Uploaded on

High Level in 2 parts. High-Level Functions for File I/O:. dlmread ()  Numerical Array only xlsread ()  Numerical AND/OR cell-arrays variables!!!. Cell Arrays. Definition Creating Cell Arrays Referencing Cell Arrays Augmenting Cell Arrays Slicing Cell Arrays. Data Types.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'High Level in 2 parts' - tamera


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
high level in 2 parts
High Level in 2 parts

High-Level Functions for File I/O:

dlmread()  Numerical Array only

xlsread()  Numerical AND/OR cell-arrays variables!!!

cell arrays

Cell Arrays

Definition

Creating Cell Arrays

Referencing Cell Arrays

Augmenting Cell Arrays

Slicing Cell Arrays

data types
Data Types
  • Recall the workspace frame in MATLAB. Currently, 3 types of data have been seen. They are called:
  • This tutorial teaches a new data type called cell-arrays

char (strings)

double (float) or int8, int16…

logical

1 cell arrays definition
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

quick vocabulary
Quick Vocabulary

Parentheses ( )

Brackets [ ]

Braces { }

2 creating cell arrays
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!

2 creating cell arrays cont
2. Creating Cell Arrays, cont.
  • Visualize them using cellplot()!

FYI: It is just a representation. J is in the first box, o in the second, e in the third.

2 creating cell arrays cont1
2. Creating Cell Arrays, cont.
  • Cell arrays can be of higher dimensions

a 2 by 2 cell array

test your understanding
Test your understanding

Is this cell array, A = {1:4; 2:3}, rectangular?

Answer: Yes, it is rectangular. Its size is 2 by 1.

3 referencing cell arrays
3. Referencing Cell Arrays
  • Like with numerical arrays, row and column indices are used
  • Unlike numerical 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

3 referencing cell arrays1
3. Referencing Cell Arrays

Parentheses

property of the cell is shown, not content

3 referencing cell arrays2
3. Referencing Cell Arrays

Curly Braces

Content in the cell

3 referencing cell arrays3
3. Referencing Cell Arrays

This becomes important when wanting to use the values!

>> x = cellmat(1,1);

>> y = x+5;

Undefined function 'plus' for input arguments of type 'cell'.

3 referencing cell arrays4
3. Referencing Cell Arrays

>> x = cellmat(1,1);

>> y = x+5; ✗

>> x = cellmat{1,1};

>> y = x+5;

y =

6 8 10 12

3 referencing cell arrays5
3. Referencing Cell Arrays

This becomes important when wanting to print values!

>> fprintf('%d\n',cellmat(2,1));

Error using fprintf

Function is not defined for 'cell' inputs.

>> fprintf('%s\n', cellmat(2,2));

Error using fprintf

Function is not defined for 'cell' inputs.

3 referencing cell arrays6
3. Referencing Cell Arrays

>> fprintf('%d\n',cellmat{2,1});

20

>> fprintf('%s\n', cellmat{2,2});

Hello

3 referencing cell arrays7
3. Referencing Cell Arrays

Cell indexing: ( )

Content indexing: { }

4 cell arrays augmenting
4. Cell Arrays – Augmenting
  • Add the string 'def'.

??

4 cell arrays augmenting1
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...

4 cell arrays augmenting2
4. Cell Arrays – Augmenting
  • Instead, augment using square brackets
4 cell arrays augmenting3
4. Cell Arrays – Augmenting
  • Add a row? Of course!
  • Like with arrays, use ; to add a new row.
5 slicing cell arrays
5. Slicing Cell-Arrays
  • Remember that the content of 1 cell is NOT connected to the content of another cell.

  • Slicing the content is not practical.
  • However, slicing the cells (i.e. containers) remains the same.
5 slicing cell arrays1
5. Slicing Cell-Arrays
  • Slicing the ages

"slicing the cells" "slicing the content"

data

6 more operations
6. More Operations…

cellplot(c)

  • Given c = {7,-2.2,'Joe',3.4,'def'}
    • Delete the 5th cell

c(5) = [];

    • Emptying contents of the 2nd cell

c{2} = [];

    • Replace 3rd cell with the cell of content 'sam';

c{3}= 'sam'; or c(3)={'sam'};

    • Change content of 1st cell to the number 8

c{1}= 8; or c(1)={8};

    • Transpose, ', still works.

c=c';

6 more operations cont
6. More Operations… (cont.)
  • Using a cell-array of numerical values????

x

6 more operations cont1
6. More Operations… (cont.)
  • Convert a cell-array of numbers to a matrix: cell2mat()

x1

x

7 why cell arrays
7. 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?
key ideas
Key Ideas
  • Cells arrays are ‘container-ships’ -- arrays of cells that allow storage of different data-types into 1 variable.
  • Cell-arrays have 3 different syntaxes:

Creating: Braces { }

Augmenting: Brackets [ ]

Referencing content: Braces { }

Referencing cells: Parentheses ()

  • Slicing can be a challenge. Do NOT slice the content.
  • Use cell2mat() to convert a cell-array of numbers to a matrix