101827-FS2017-0: Programming With MATLAB: Advanced Course: Felix Wichmann

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

101827-FS2017-0:


Programming with MATLAB:



Advanced course
Felix Wichmann

Neural Information Processing Group and

Bernstein Center for Computational Neuroscience, 

Eberhard Karls Universität Tübingen &

Max Planck Institute for Intelligent Systems, Tübingen
1: structs and cells
Essential functions and concepts for today
Thus far the only datatype we have covered is the array — in form of
scaler (1-by-1), vector (N-by-1 or 1-by-N) or matrix (N-by-M).
Arrays clearly comes from the old days in MATLAB, as it was a language for
number crunching only: every entry in an array can only be one “unit” and
they all have to be of the same type (typically a number, could be a string).
For “real” data of (psychological) experiments this is clearly limiting: we
would like to store the name of our observers, perhaps their age, the
performance in a task, reaction times etc. all within one “data container”.

MATLAB supports two more advanced data formats: struct and cell

(a few more in recent years; we may come back to them in seminar no. 6).

Important functions to know: fieldnames, setfield, getfield,


struct, isfield, orderfields, rmfield, isstruct, cell,
celldisp, iscell, input, tic, toc

3
Essential functions and concepts for today (cont’d)
Functions that are useful to know are:

- conversion functions like cell2mat, mat2cell, cell2struct

- as well as functions for quickly applying function to all entries of a struct
or cell (cellfun, structfun).

4
Detailed instructions for this morning
0. If you feel like a refresher: Watch the following (quick and dense!) video
tutorials on software-carpentry.org

(http://swcarpentry.github.io/v4/matlab/index.html) and have a
look at: Introduction, Basics, Indexing, Basic Flow Control and More Flow
Control

1. Flow Control: for versus while. Please have a look at the script
DiceGame.m I have uploaded to ILIAS.
2. Read and work through MATLAB Programming/Arrays.pdf
3. Read and work through MATLAB Programming/Struct Arrays.pdf
4. Read and work through MATLAB Programming/Cell Arrays.pdf

5
Detailed instructions for this morning (cont’d)
5. Read and work through StructuresAndCellArrays-Excerpt.pdf—do not
worry if there are references to particular files or functions you do not
have.
6. Read and work through Strings_Cells_Structs-Excerpt.pdf 

pp. 1–3: Repeat and extended treatment of functions to manipulate
strings

pp. 4–7: About cells; do not worry too long about cellfunctions on p. 7

pp. 7–11: More on string manipulation—please SKIP this part

pp. 11-14: About structs

Stop on p. 14 and do not read (or worry) about Containers.map
7. Watch Structures and Cell Arrays on software-carpentry.org:

http://swcarpentry.github.io/v4/matlab/cellarrays.html

6
Homework
Download 01-Struct-Cell_Exercises.pdf from ILIAS and do the exercises.
On Thursday the 22nd of May I upload the solutions for you to look at, and
compare your own answers to my solutions.

You might also like