Cross-modal’ reward signals in primary visual and

Download Report

Transcript Cross-modal’ reward signals in primary visual and

MATLAB: An introduction
Markus Bauer,
UCL Institute of Cognitive Neuroscience
University College London
(previous version:Christian Ruff)
[email protected]
Course overview
•
Autumn 2009: Using MATLAB for data analysis and visualisation
–
–
–
–
–
Session 1: Basics of MATLAB / Programming
Session 2: Basics of MATLAB / Programming
Session 3: Handling and Importing of data & analysis
Session 4: Visualization in MATLAB
Session 5: Tips and tricks, questions and answers
•
Spring 2010: Using MATLAB to run experiments and collect data
•
Summer 2010: Advanced experimental and data analysis procedures
 All materials online at
http://www.icn.ucl.ac.uk/courses/MATLAB-Tutorials/index.htm
What is MATLAB?
•
“MATrix LABoratory”, a high-level programming language / computing environment
•
Enables efficient programming of mathematical operations, in particular for matrixoperations
•
Similar to programming languages as ‘C’, but easier to use (variable definitions etc)
•
Advanced visualization tools --> Graphs and plotting data
•
Many specialised toolboxes available (e.g., statistics; image processing, etc.) + code for
specific scientific purposes freely available on the internet (e.g., COGENT, SPM)
•
Transparent way of analysing data -> full access to data on all levels (no ‘black box’),
easy to modify / build up on existing tools
•
Can make GUI based software environments
•
•
•
Disadvantages:
It is expensive (but see Octave)
It can be slow (can partially be compensated by using MEX functions, compiled)
How do I get started?
•
http://www.mathworks.com
• http://www.gnu.org/software/octave/ (free software)
•
Excellent documentation and tutorial (both online and in pdf form) at
http://www.mathworks.com/support/ or by typing help or doc in MATLAB
•
Other MATLAB tutorials on the web:
– http://www.icn.ucl.ac.uk/webspace/users/ahamilton/matlab.htm
– http://www.mrc-cbu.cam.ac.uk/Imaging/Common/matlab.shtml
– http://www.indiana.edu/~statmath/math/matlab/
•
A good book: “Mastering Matlab” by Hanselmann and Littlefield
•
Lots of functions at http://www.mathworks.com/matlabcentral/
Basics of MATLAB
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
- matlab windows - desktop - command window, history and workspace
Show the matlab command window:
Can use as a calculator, or to ‘interactively’ enter commands
Show history function and the tab
Where are functions - path definition and the startup file
Matlab functions and scripts: = programs
Matlab editor: a text editor
Essentials of programming:
Variables and arrays: numerical variables (integer and double), strings / string arrays
• Cell arrays, structures
- built in functions (e.g. fprintf, open, save etc)
Operators: + - * / ^ logical operators: & | ~ others: () [] {} , ; :
Conditional statements : if ... elseif ... end
Loops:
For ((to)) end loop
While (conditional statement) end loop
Distinction: script and function
Demo: Functions
• Functions: function [output1,output2,…] = myfun(input1, input2,…)
• Functions:
– Input needs to be defined in command, output not
– Function workspace: a separate module of the workspace
• contains inputs to functions, transformation variables, and outputs from
function
• These variables are not visible from the global workspace
• Functions can call other functions and contain subfunctions
– Commands without semicolon are visible in command window
– Graphical output is visible
Demo: Functions in MATLAB
• MATLAB – just a collection of functions:
– Built-in functions cannot be edited but have an .m-file (for help)
– Add-on functions are just an ordinary .m file that you can see/edit/add
• How MATLAB finds a function:
–
–
–
–
Embedded in the function as subfunction
Built-in functions
Local directory
Path in descending order
• Add functions to directory outside of the MATLAB toolbox (e.g.,
‘work’ – otherwise MATLAB might overwrite them when re-installed
• Dependency report