dafni

Brain images + timecourses in Matlab

The aims of this lesson are:

Matlab, two ways…

makeMontage()

For the first part of the session, I will do a coding walk-through with some narrated advice on problem solving, etc. In the second part of the session, you will then apply the ideas from the first part of make your own function for extracting timecourses from data.

example of a montage

If you want, you can also have a more detailed look at the files and exercises in the matlab_images folder.

getTimecourse()

In the second part of the session, we want you to make use of the ideas we introduced in the first part to:

%  tcourse = returnTimecourse(data, xcoord, ycoord, zcoord);
% so you can use it with 
cd('fmri.feat') % go into the folder
data = niftiread('filtered_func_data.nii.gz');

% use it like this...
t = returnTimecourse(data, 30, 5, 2);
plot(t, 'linewidth',2)
xlabel('Time'); 
ylabel('fMRI response')

correct version

if you get the following…

not quite version

plot() throws errors

if you don’t have the feat folder

You can try to download my version from this link [requires UoN login]

Follow-up, solutions

x = [30,31,32]; 
y = [5,5,5]; 
z = [2,2,2];
t = [1, 1, 1];
linear_idx = sub2ind(size(data),x,y,z,t);

% then
tcourses = data_snake(linear_idx,:);
% make sure they are columns
tcourses = tcourses';

figure()
plot(tcourses);