Brace indexing is not supported for variables of this type.

8 views (last 30 days)
Dear Matlab communities:
I am running a spm script for analyizing neuroimaging data, the first script here (ModelSpecificationBinaryMask.m) is to loop another job file ModelSpecificationBinaryMask_job.m over the two subjects while assigning the regressor files that correspond to each of the runs for one subject.
However, I am seeing the follwing errors:
Brace indexing is not supported for variables of this type.
Error in spm_jobman>canonicalise_jobs (line 415)
comp(i) = comp(i) && any(strcmp(fieldnames(job{i}{j}), ...
Error in spm_jobman (line 152)
mljob = canonicalise_jobs(jobs);
Error in ModelSpecificationBinaryMask (line 50)
spm_jobman('run', jobs, inputs);
ModelSpecificationBinaryMask.m
clear
close all
clc
% Created by GB on 9/9/19.
% Edited by LC on 8/19/24.
for sub = [101,102]
jobfile = {'/Volumes/PUMPKIN/scripts/GabbyScripts/ModelSpecificationBinaryMaskTHRESHOFF_job.m'};
nrun = 1; % Assuming nrun should be 1 since we are processing one subject at a time
ncue = 8; % 8 runs for cue task
jobs = repmat(jobfile, 1, nrun);
inputs = cell(25, 1); % Initialize cell array for inputs (25 because you have 3 inputs per run and 8 runs)
% Create a homepath, a base location of all the data
homepath = '/Volumes/PUMPKIN/Preprocessed/groupA/Volumes';
evpath = '/Volumes/PUMPKIN/Regressors';
for n = 1:nrun
sub_path = fullfile('/Volumes/PUMPKIN/halfpipeXspm/sub-', num2str(sub(n)), '/1stLevel');
%mkdir(sub_path);
inputs{1, n} = {sub_path}; % fMRI model specification: Directory - cfg_files
% Loop through each run for the subject
for run = 1:ncue
run_dir = fullfile(homepath, strcat('sub_', num2str(sub(n))), '-', num2str(run));
% List all 'vol_*.nii' files in the current folder
files = dir(fullfile(run_dir, 'vol_*.nii'));
if ~isempty(files)
% Now assign images
inputs{2+(run-1)*3, n} = {fullfile(run_dir, {files.name})}; % fMRI model specification: Scans - cfg_files
% Insert multiple condition files (i.e., evs)
ev_file = dir(fullfile(evpath, strcat('sub', num2str(sub(n)), 'run', num2str(run), '_exev_CS_faceCue.mat')));
inputs{3+(run-1)*3, n} = {fullfile(evpath, ev_file.name)};
% Insert multiple regressors (6 rigid body motion parameters)
rp_file = dir(fullfile(run_dir, 'rp_af*.txt'));
inputs{4+(run-1)*3, n} = {fullfile(run_dir, rp_file.name)};
end
clear files rp_file
end
clear currfold
end
% Run the job using SPM
spm_jobman('run', jobs, inputs);
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% ModelSpecificationBinaryMask_job.m
%-----------------------------------------------------------------------
% Job saved on 17-Jun-2016 14:21:03 by cfg_util (rev $Rev: 6134 $)
% spm SPM - SPM12 (6225)
% cfg_basicio BasicIO - Unknown
%-----------------------------------------------------------------------
disp('Script is running');
matlabbatch(1).spm.stats.fmri_spec.dir = {'/Volumes/PUMPKIN/halfpipeXspm/sub-*/1stLevel'};
matlabbatch(1).spm.stats.fmri_spec.timing.units = 'secs';
matlabbatch(1).spm.stats.fmri_spec.timing.RT = 2;
matlabbatch(1).spm.stats.fmri_spec.timing.fmri_t = 32;
matlabbatch(1).spm.stats.fmri_spec.timing.fmri_t0 = 1;
matlabbatch(1).spm.stats.fmri_spec.sess(1).scans = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(1).cond = struct('name', {}, 'onset', {}, 'duration', {}, 'tmod', {}, 'pmod', {}, 'orth', {});
matlabbatch(1).spm.stats.fmri_spec.sess(1).multi = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(1).regress = struct('name', {}, 'val', {});
matlabbatch(1).spm.stats.fmri_spec.sess(1).multi_reg = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(1).hpf = 128;
matlabbatch(1).spm.stats.fmri_spec.sess(2).scans = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(2).cond = struct('name', {}, 'onset', {}, 'duration', {}, 'tmod', {}, 'pmod', {}, 'orth', {});
matlabbatch(1).spm.stats.fmri_spec.sess(2).multi ='<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(2).regress = struct('name', {}, 'val', {});
matlabbatch(1).spm.stats.fmri_spec.sess(2).multi_reg = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(2).hpf = 128;
matlabbatch(1).spm.stats.fmri_spec.sess(3).scans = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(3).cond = struct('name', {}, 'onset', {}, 'duration', {}, 'tmod', {}, 'pmod', {}, 'orth', {});
matlabbatch(1).spm.stats.fmri_spec.sess(3).multi = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(3).regress = struct('name', {}, 'val', {});
matlabbatch(1).spm.stats.fmri_spec.sess(3).multi_reg = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(3).hpf = 128;
matlabbatch(1).spm.stats.fmri_spec.sess(4).scans = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(4).cond = struct('name', {}, 'onset', {}, 'duration', {}, 'tmod', {}, 'pmod', {}, 'orth', {});
matlabbatch(1).spm.stats.fmri_spec.sess(4).multi = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(4).regress = struct('name', {}, 'val', {});
matlabbatch(1).spm.stats.fmri_spec.sess(4).multi_reg = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(4).hpf = 128;
matlabbatch(1).spm.stats.fmri_spec.sess(5).scans = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(5).cond = struct('name', {}, 'onset', {}, 'duration', {}, 'tmod', {}, 'pmod', {}, 'orth', {});
matlabbatch(1).spm.stats.fmri_spec.sess(5).multi = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(5).regress = struct('name', {}, 'val', {});
matlabbatch(1).spm.stats.fmri_spec.sess(5).multi_reg = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(5).hpf = 128;
matlabbatch(1).spm.stats.fmri_spec.sess(6).scans = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(6).cond = struct('name', {}, 'onset', {}, 'duration', {}, 'tmod', {}, 'pmod', {}, 'orth', {});
matlabbatch(1).spm.stats.fmri_spec.sess(6).multi = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(6).regress = struct('name', {}, 'val', {});
matlabbatch(1).spm.stats.fmri_spec.sess(6).multi_reg = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(6).hpf = 128;
matlabbatch(1).spm.stats.fmri_spec.sess(7).scans = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(7).cond = struct('name', {}, 'onset', {}, 'duration', {}, 'tmod', {}, 'pmod', {}, 'orth', {});
matlabbatch(1).spm.stats.fmri_spec.sess(7).multi ='<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(7).regress = struct('name', {}, 'val', {});
matlabbatch(1).spm.stats.fmri_spec.sess(7).multi_reg = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(7).hpf = 128;
matlabbatch(1).spm.stats.fmri_spec.sess(8).scans = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(8).cond = struct('name', {}, 'onset', {}, 'duration', {}, 'tmod', {}, 'pmod', {}, 'orth', {});
matlabbatch(1).spm.stats.fmri_spec.sess(8).multi = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(8).regress = struct('name', {}, 'val', {});
matlabbatch(1).spm.stats.fmri_spec.sess(8).multi_reg = '<UNDEFINED>';
matlabbatch(1).spm.stats.fmri_spec.sess(8).hpf = 128;
matlabbatch(1).spm.stats.fmri_spec.fact = struct('name', {}, 'levels', {});
matlabbatch(1).spm.stats.fmri_spec.bases.hrf.derivs = [0 0];
matlabbatch(1).spm.stats.fmri_spec.volt = 1;
matlabbatch(1).spm.stats.fmri_spec.global = 'None';
matlabbatch(1).spm.stats.fmri_spec.mthresh = 0.0; %no voxels are thresholded so all voxels are being used%
matlabbatch(1).spm.stats.fmri_spec.mask = {'/Volumes/PUMPKIN/scripts/LancyScripts/peripheral/C1-101-117/binarygreymattermask.nii'};
matlabbatch(1).spm.stats.fmri_spec.cvi = 'AR(1)';
disp('Script completed');

Answers (2)

Umang Pandey
Umang Pandey on 19 Aug 2024
Hi,
The error message "Brace indexing is not supported for variables of this type" suggests that you are trying to use brace indexing on a variable that does not support it. Brace indexing is used to access elements of a cell array or structure array using curly braces {}. However, it seems that the variable you are trying to index does not have the appropriate data type for brace indexing.
To resolve this issue, you need to identify the variable that is causing the error and check its data type. Make sure that the variable is a cell array or structure array before using brace indexing on it.
Here are a few possible reasons for this error:
  1. The variable 'comp' in the 'canonicalise_jobs' function is not a cell array or structure array.
  2. The variable 'job{i}{j}' in the 'canonicalise_jobs' function is not a cell array or structure array.
To debug this issue, you can add some print statements or use the MATLAB debugger to inspect the variables and their data types at the point of the error.
  1 Comment
Voss
Voss on 19 Aug 2024
Brace indexing is not supported for structure arrays:
% use a cell array as an input to struct() to create a structure array S
S = struct('ok',{1 2})
S = 1x2 struct array with fields:
ok
% check the individual elements of S
S(1)
ans = struct with fields:
ok: 1
S(2)
ans = struct with fields:
ok: 2
% try brace indexing on S
S{1}
Brace indexing is not supported for variables of this type.
Among the built-in data types, brace indexing is supported for cell arrays and tables, with table indexing always requiring two subscripts.

Sign in to comment.


Saurav
Saurav on 19 Aug 2024
Edited: Saurav on 19 Aug 2024
The error, "Brace indexing is not supported for variables of this type," suggests that there might be an issue with how the ‘inputs’ variable is being used.
Here are a few suggestions to help you debug and potentially resolve the issue:
Indexing errors:
  1. Ensure that the ‘inputs’ variable is being indexed correctly. In the code, 'inputs' is a cell array initialized with 'inputs = cell(25, 1);'.This means it is expected to be a column vector with 25 elements, but in the loop, it is being accessed with two indices (inputs{1, n}).Since 'nrun' is set to 1, indexing can be simplified to use a single index, or ensure that 'inputs' is set up to accommodate two-dimensional indexing if necessary.
Debugging
  1. Add debugging statements to print the contents and types of variables before the line that causes the error. This can help identify where the mismatch is occurring.
  2. If the line of code giving the error has executed correctly before, then what I would look for is the possibility that a variable has become empty. MATLAB debugger can be used to inspect the variables and their data types.
Function Execution:
  1. Ensure that the structure of 'jobs' and 'inputs' matches what spm_jobman('run', jobs, inputs) expects. The 'jobfile' should be a valid path to a job configuration script and the 'inputs' should match the job's expected input format.
  2. You can also add some checks to ensure that the files exist before attempting to access their names. For instance:
if ~isempty(ev_file)
inputs{3+(run-1)*3, n} = {fullfile(evpath, ev_file.name)};
else
error('EV file not found for subject %d run %d', sub(n), run);
end
if ~isempty(rp_file)
inputs{4+(run-1)*3, n} = {fullfile(run_dir, rp_file.name)};
else
error('RP file not found for subject %d run %d', sub(n), run);
end
Thanks,
Saurav.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!