Seeking Guidance on Creating a Proper .mat File with Multiple Conditions for SPM 12 fMRI Analysis

51 views Asked by At

Hello Stack Overflow community,

I am currently working on first level fMRI analysis using SPM 12 and am facing challenges in creating a proper .mat file that accommodates multiple conditions.

In my experiment, I am dealing with three conditions: unpleasant, neutral, and pleasant. Each condition has multiple trials, and in total, there are 90 trials. The duration of each stimulus (trial) is fixed at 6 seconds. I have organized all this data in an Excel (.xlsx) file, and I am in the process of converting it into a .mat file for compatibility with SPM fMRI analysis.

I have tried the following the code to convert the data into .mat file.

data = readtable('xxx_xxx_run2-IADS_list2.xlsx', 'Sheet', 2);

% Define conditions
conditionLabels = {'u', 'n', 'p'};
numConditions = numel(conditionLabels);

% Preallocate cell arrays for onsets and durations
onsets = cell(1, numConditions);
durations = cell(1, numConditions);

% Loop through the rows
for i = 1:height(data)
    % Check the condition based on the first column
    condition = data{i, 1};
    
    % Find the index of the condition label
    conditionIndex = find(strcmp(conditionLabels, condition));
    
    % Update the corresponding cell arrays
    if ~isempty(conditionIndex)
        onsets{conditionIndex}{end+1} = data{i, 2};
        durations{conditionIndex}{end+1} = data{i, 3};
    else
        % Handle other conditions if needed
    end
end

% Consolidate names, onsets, and durations
names = conditionLabels;

% Save the lists to a MAT-file
save('conditions.mat', 'names', 'onsets', 'durations');

However, when I attempt to use this .mat file in SPM for fMRI analysis, I encounter the following errors.

Error using min
Invalid data type. First argument must be numeric or logical.
In file "C:\Users\jnami\spm12\spm12\spm_get_ons.m" (v4855), function "spm_get_ons" at line 87.
In file "C:\Users\jnami\spm12\spm12\spm_fMRI_design.m" (v7739), function "spm_fMRI_design" at line 221.
In file "C:\Users\jnami\spm12\spm12\spm_fmri_spm_ui.m" (v7738), function "spm_fmri_spm_ui" at line 183.
In file "C:\Users\jnami\spm12\spm12\config\spm_run_fmri_spec.m" (v7739), function "spm_run_fmri_spec" at line 386.
0

There are 0 answers