Class Notes (1,100,000)
CA (630,000)
UTSC (30,000)
Psychology (8,000)
Lecture 8

PSYB03H3 Lecture 8: Cell Arrays/Implementing an Experiment


Department
Psychology
Course Code
PSYB03H3
Professor
Adrian Nestor
Lecture
8

This preview shows pages 1-2. to view the full 6 pages of the document.
PSYB03: Introduction to Computers in Psychological Research Clara Rebello
PSYB03 Lecture 8: Cell Arrays/Implementing an Experiment
Cell arrays: Arrays of data of different types
o Commonly used for storing strings and numbers together
o Example: A 2 x 3 cell array of names and ages
Information is arranged by columns
Creating cell array
o Cell construction operator
o You can build it form scratch
>> C = {‘John’ ‘Sam’ ‘Kate’;23 19 21}
o You can also preallocate memory for an array and then populate it
Cell(n,m): Creates an empty n x m cell array
Concatenating multiple arrays
o >>A(1,1:3)={‘John’ ‘Sam’ ‘Kate’};
o >>B(1,1:3)={23 19 21};
o >>C=[A;B]
o You can note which subjects should be included in the analysis Logical array
>>D=[A;B;{true false true}]
Will remove the 2nd subject
Cells of a cell array can be entire matrices
o
o Command window will display ‘[2x2 double]’ because it isn’t feasible to show a large
chunk of information in a small space
o You can still see under the variables window what elements the cell with the matrix
contains
Cells of a cell array can be other cell arrays
o
Accessing a cell array

Only pages 1-2 are available for preview. Some parts have been intentionally blurred.

PSYB03: Introduction to Computers in Psychological Research Clara Rebello
o
o It’s easy to believe that ‘John’ is a string
However, it isn’t; when confirming its class using the class command, you get
‘cell’
Cell ≠ string
Accessing the contents of a cell
o Using {} instead of () provides content indexing Unpacks a cell
o Example:
Note that when using {} to index the content, then checking the class of the
variable a, it comes up as character instead of cell
Accessing the contents of multiple cells
o Do so by assigning values to a comma-separated list
o Specify the variables within square brackets, then assign them values
o Example:
Converting cell arrays
o Cell2mat: Converts a cell array into an ordinary array; Elements of the cell array must all
contain the same data type/class, and the resulting array is of that data type
o
o Example:
You're Reading a Preview

Unlock to view full version