Indexing (many rows, columns)
a = [1, 2, 3;
4, 5, 6]
what does the following do?
a([1 2],1) % elements at row=[1 2], column=1
a([1 2],[1 3]) % elements at rows 1 and 2, columns 1 and 3
Indexing (tricks)
Special tricks to get hold of all rows/columns :
(colon)
a = [1, 2, 3;
4, 5, 6]
specify all rows
a(:,1) % elements for ALL rows, column=1
or all til the end of the matrix
a(1, 2:end ) % elements at row 1 , columns 2 to end
2 dimensions
rows then
columns
the order in which we think about the data is important!
more than 2 dimensions
rows, columns, 3 dim, [more dimensions]
can think of those by analogy to an Excel spreadsheet?
rows, columns, sheets, ...
More than 2 dimensions
- many kinds of data have more than 2d
- anatomical brain images: 3d (many 2d images)
- fMRI data: 4d (many 3d volumes)
- can you think of others?
- Matlab handles these easily::
V = rand(10, 10, 5); % 10-by-10-by-5 array
V(7,8,2) % returns element at that index
Storing things other than numbers
- other kinds of data, not just "numbers"
- e.g. text is stored as character strings
- more abstract data types:
struct
,cell
, - we'll meet some of them later