Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Creating a clear and efficient script

Jie Fu https://sites.google.com/site/bigaidream/ Friday, February 8, 2013


Based on http://fieldtrip.fcdonders.nl/tutorial/scripting [KEY] Batching is the ultimate aim of any analysis pipeline.

Subject m-files
By making our own function around FieldTrip functions we can in a later stage easily repeat them, e.g. over multiple subjects. However, every subject or condition will commonly have different filenames, different variables, different filter-settings, different trials that have to be rejected, etc. A good idea, therefore, is to first write all your subject-specific details in a separate m-file.

Making your own analysis functions


[KEY] Store a single variable per file. This will in general make it possible to more easily only read what is necessary.

Batching

Try Catch

Dealing with memory issues


Load only as much data as you need Avoid creating temporary arrays A = zeros(1e6,1); As = single(A); use just the one command to do both operations: A = zeros(1e6,1,'single'); Use nested functions to pass fewer arguments A nested function shares the workspace of all outer functions, giving the nested function access to data outside of its usual scope. In the example shown here, nested function setrowval has direct access to the workspace of the outer function myfun, making it unnecessary to pass a copy of the variable in the function call. When setrowval modifies the value of A, it modifies it in the workspace of the calling function. There is no need to use additional memory to hold a separate array for the function being called, and there also is no need to return the modified value of A: function myfun A = magic(500); function setrowval(row, value) A(row,:) = value; end setrowval(400, 0); disp('The new value of A(399:401,1:10) is') A(399:401,1:10) end

You might also like