tags:

views:

36

answers:

0

hello, I am a newby writing a script and I am facing what I think should not be difficutl to solve...

this script is to:

1)extract 4 different fmri onsets from matlab files (the files are named 'subject 06 data', 'subject 05 data', etc...)

2)put this information in a new file with 2 other variables named 'durations' and 'names'

3)save all this as a new matlab file.

I am facing 2 problems:

At the moment the script below manages to do steps 1)==>3 for the first matlab file in the directory'Gender_recogntion', but does not do 1)==>3) for the other matlab files in the folder: it crashes in the loop at the line 'load(sub_name(i).name);'.

This is the error I get:

??? Improper index matrix reference.

Error in ==> Gender_onsets_script_2 at 16 load(sub_name(i).name);

In addtion, I would like to name the new matlab files with the name of the original matlab files. At the moment, the new matlab files is named 'onsets.mat'.

Any help would be greatly appreciated

thanks

steph'

clear all
close all
clc

cd 'C:\Program Files\MATLAB\R2007b\Data\Resilience\Real_data\Raw\Matlab_files\Gender_recogntion';


sub_name = dir('C:\Program Files\MATLAB\R2007b\Data\Resilience\Real_data\Raw\Matlab_files\Gender_recogntion\*.mat');


  for i = 1:numel(sub_name);
     load(sub_name(i).name);

     names = {'sad' 'anger' 'neutral' 'rest'};
     durations = {[18] [18] [18] [18]};
     onsets=cell(1,4);


     onsets{1} = data.time_since_scan_start(data.emotion==5)/1000; %get the 36 onsets for sad
     onsets{2} = data.time_since_scan_start(data.emotion==4)/1000; %get the 36 onsets for anger
     onsets{3} = data.time_since_scan_start(data.emotion==6)/1000;% get the 36 onsets for calm
     onsets{4} = datarest.onset/1000; %get the 6 onsets for the rest blocks


     onsets{1} = onsets{1}(1:6:36)'; %get the first onset value of each of the 6 blocks
     onsets{2} = onsets{2}(1:6:36)';
     onsets{3} = onsets{3}(1:6:36)';
     onsets{4} = onsets{4}';

     %cd Onsets folder, saves onsets, and then cd back to Matlab_files
     cd 'C:\Program Files\MATLAB\R2007b\Data\Resilience\Real_data\Onsets';
     save 'onsets.mat' names durations onsets
     cd 'C:\Program Files\MATLAB\R2007b\Data\Resilience\Real_data\Raw\Matlab_files\Gender_recogntion';

end

related questions