0% found this document useful (0 votes)
382 views2 pages

Creating A Clear and Efficient Script

The document discusses strategies for creating efficient scripts for analyzing neuroimaging data. It recommends batching analyses to process multiple subjects or conditions simultaneously. It also suggests writing subject-specific details in separate files and storing single variables per file to only load necessary data. The document advises using try-catch blocks and nested functions to avoid memory issues by passing fewer arguments and sharing workspace.

Uploaded by

Jie Fu
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
382 views2 pages

Creating A Clear and Efficient Script

The document discusses strategies for creating efficient scripts for analyzing neuroimaging data. It recommends batching analyses to process multiple subjects or conditions simultaneously. It also suggests writing subject-specific details in separate files and storing single variables per file to only load necessary data. The document advises using try-catch blocks and nested functions to avoid memory issues by passing fewer arguments and sharing workspace.

Uploaded by

Jie Fu
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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