help > Event-related conditions with batch
Showing 1-8 of 8 posts
Mar 27, 2020 02:03 AM | Kaitlin Cassady - University of Michigan - Ann Arbor
Event-related conditions with batch
Hello!
I have an event-related design and have 7 conditions and 1 run (concatenated from 2 runs) for each subject. I'm using batch code to run my analyses. I've been able to load the conditions names just fine, but I'm having trouble loading in the onsets and durations.
I don't get any errors, but when the GUI opens up to SETUP --> Conditions, I see that the "Condition Definition" is still "condition spans the entire session". What is the batch command to change this to "specify blocks/events within selected session." Also, how can I load in my specific onsets and durations from a .mat file?
This is what I have for my batch code so far:
------------------------
% Load onsets mat
load([logDir,'BAC001_onsets_icontext_basic.mat']); % Loads subjects conditon names and onsets (duration is 0)
ncon=length(CondNames); %7 condis
nses = 2; % 2 runs but need to concatenate to just one
onsets=onsets_basic;
N_EPIs_run=313; %number EPIs per run
r=1; %1 run sicne concatenated
C=0;
%each run modelled, set Conditons and onsets
for Con=1:length(CondNames)
if nses==2
onsets_concat=[onsets{1,Con},onsets{2,Con}+TR*N_EPIs_run ]; %concat the onsets
else
onsets_concat=[onsets{1,Con} ]; %concat the onsets
end
if isempty([onsets_concat])==0 && length([onsets_concat])>3 %if not empty and enough trials
disp(CondNames{Con});
C=C+1; %count upwards
batch.Setup.conditions.names{Con}=CondNames{Con};
batch.Setup.conditions.onsetss{ncon}{nsub}{nses}=abs(onsets_concat);
batch.Setup.conditions.durationss{ncon}{nsub}{nses}=0;
else
error([CondNames{Con}, ' EMPTY or less than 3 trials across runs!!'])
end
end
------------------------
Any help would be greatly appreciated - thank you!
I have an event-related design and have 7 conditions and 1 run (concatenated from 2 runs) for each subject. I'm using batch code to run my analyses. I've been able to load the conditions names just fine, but I'm having trouble loading in the onsets and durations.
I don't get any errors, but when the GUI opens up to SETUP --> Conditions, I see that the "Condition Definition" is still "condition spans the entire session". What is the batch command to change this to "specify blocks/events within selected session." Also, how can I load in my specific onsets and durations from a .mat file?
This is what I have for my batch code so far:
------------------------
% Load onsets mat
load([logDir,'BAC001_onsets_icontext_basic.mat']); % Loads subjects conditon names and onsets (duration is 0)
ncon=length(CondNames); %7 condis
nses = 2; % 2 runs but need to concatenate to just one
onsets=onsets_basic;
N_EPIs_run=313; %number EPIs per run
r=1; %1 run sicne concatenated
C=0;
%each run modelled, set Conditons and onsets
for Con=1:length(CondNames)
if nses==2
onsets_concat=[onsets{1,Con},onsets{2,Con}+TR*N_EPIs_run ]; %concat the onsets
else
onsets_concat=[onsets{1,Con} ]; %concat the onsets
end
if isempty([onsets_concat])==0 && length([onsets_concat])>3 %if not empty and enough trials
disp(CondNames{Con});
C=C+1; %count upwards
batch.Setup.conditions.names{Con}=CondNames{Con};
batch.Setup.conditions.onsetss{ncon}{nsub}{nses}=abs(onsets_concat);
batch.Setup.conditions.durationss{ncon}{nsub}{nses}=0;
else
error([CondNames{Con}, ' EMPTY or less than 3 trials across runs!!'])
end
end
------------------------
Any help would be greatly appreciated - thank you!
Mar 27, 2020 03:03 PM | Alfonso Nieto-Castanon - Boston University
RE: Event-related conditions with batch
Hi Kaitlin,
the lines:
batch.Setup.conditions.onsetss{ncon}{nsub}{nses}=abs(onsets_concat);
batch.Setup.conditions.durationss{ncon}{nsub}{nses}=0;
should probably read:
batch.Setup.conditions.onsets{Con}{nsub}{nses}=abs(onsets_concat);
batch.Setup.conditions.durations{Con}{nsub}{nses}=0;
Best
Alfonso
ps. also, in general, I would probably recommend not to concatenate your multiple runs, and simply enter them as different sessions instead, e.g.
batch.Setup.conditions.onsets{Con}{nsub}=onsets(:,Con);
Originally posted by Kaitlin Cassady:
the lines:
batch.Setup.conditions.onsetss{ncon}{nsub}{nses}=abs(onsets_concat);
batch.Setup.conditions.durationss{ncon}{nsub}{nses}=0;
should probably read:
batch.Setup.conditions.onsets{Con}{nsub}{nses}=abs(onsets_concat);
batch.Setup.conditions.durations{Con}{nsub}{nses}=0;
Best
Alfonso
ps. also, in general, I would probably recommend not to concatenate your multiple runs, and simply enter them as different sessions instead, e.g.
batch.Setup.conditions.onsets{Con}{nsub}=onsets(:,Con);
Originally posted by Kaitlin Cassady:
Hello!
I have an event-related design and have 7 conditions and 1 run (concatenated from 2 runs) for each subject. I'm using batch code to run my analyses. I've been able to load the conditions names just fine, but I'm having trouble loading in the onsets and durations.
I don't get any errors, but when the GUI opens up to SETUP --> Conditions, I see that the "Condition Definition" is still "condition spans the entire session". What is the batch command to change this to "specify blocks/events within selected session." Also, how can I load in my specific onsets and durations from a .mat file?
This is what I have for my batch code so far:
------------------------
% Load onsets mat
load([logDir,'BAC001_onsets_icontext_basic.mat']); % Loads subjects conditon names and onsets (duration is 0)
ncon=length(CondNames); %7 condis
nses = 2; % 2 runs but need to concatenate to just one
onsets=onsets_basic;
N_EPIs_run=313; %number EPIs per run
r=1; %1 run sicne concatenated
C=0;
%each run modelled, set Conditons and onsets
for Con=1:length(CondNames)
if nses==2
onsets_concat=[onsets{1,Con},onsets{2,Con}+TR*N_EPIs_run ]; %concat the onsets
else
onsets_concat=[onsets{1,Con} ]; %concat the onsets
end
if isempty([onsets_concat])==0 && length([onsets_concat])>3 %if not empty and enough trials
disp(CondNames{Con});
C=C+1; %count upwards
batch.Setup.conditions.names{Con}=CondNames{Con};
batch.Setup.conditions.onsetss{ncon}{nsub}{nses}=abs(onsets_concat);
batch.Setup.conditions.durationss{ncon}{nsub}{nses}=0;
else
error([CondNames{Con}, ' EMPTY or less than 3 trials across runs!!'])
end
end
------------------------
Any help would be greatly appreciated - thank you!
I have an event-related design and have 7 conditions and 1 run (concatenated from 2 runs) for each subject. I'm using batch code to run my analyses. I've been able to load the conditions names just fine, but I'm having trouble loading in the onsets and durations.
I don't get any errors, but when the GUI opens up to SETUP --> Conditions, I see that the "Condition Definition" is still "condition spans the entire session". What is the batch command to change this to "specify blocks/events within selected session." Also, how can I load in my specific onsets and durations from a .mat file?
This is what I have for my batch code so far:
------------------------
% Load onsets mat
load([logDir,'BAC001_onsets_icontext_basic.mat']); % Loads subjects conditon names and onsets (duration is 0)
ncon=length(CondNames); %7 condis
nses = 2; % 2 runs but need to concatenate to just one
onsets=onsets_basic;
N_EPIs_run=313; %number EPIs per run
r=1; %1 run sicne concatenated
C=0;
%each run modelled, set Conditons and onsets
for Con=1:length(CondNames)
if nses==2
onsets_concat=[onsets{1,Con},onsets{2,Con}+TR*N_EPIs_run ]; %concat the onsets
else
onsets_concat=[onsets{1,Con} ]; %concat the onsets
end
if isempty([onsets_concat])==0 && length([onsets_concat])>3 %if not empty and enough trials
disp(CondNames{Con});
C=C+1; %count upwards
batch.Setup.conditions.names{Con}=CondNames{Con};
batch.Setup.conditions.onsetss{ncon}{nsub}{nses}=abs(onsets_concat);
batch.Setup.conditions.durationss{ncon}{nsub}{nses}=0;
else
error([CondNames{Con}, ' EMPTY or less than 3 trials across runs!!'])
end
end
------------------------
Any help would be greatly appreciated - thank you!
Mar 27, 2020 11:03 PM | Kaitlin Cassady - University of Michigan - Ann Arbor
RE: Event-related conditions with batch
Hi Alfonso,
Thanks so much for your quick reply! When I try to run the same code, but with two subjects with 2 sessions each, the GUI opens just fine, with both subjects added, but only 1 session gets added (with no onsets or durations) and I get a CONN error that reads:
--------------
ERROR DESCRIPTION:
Undefined function 'eq' for input arguments of type 'cell'.
Error in conn (line 3658)
if ~all(size(ko{1})==size(CONN_x.Setup.conditions.values{nsub}{ncondition}{nses}{1})) || ~all(all(ko{1}==CONN_x.Setup.conditions.values{nsub}{ncondition}{nses}{1})), ok(1)=0; end;
Error in conn (line 1499)
[varargout{1:nargout}]=conn('gui_setup',varargin{3:end});
Error in conn_menumanager (line 120)
feval(CONN_MM.MENU{n0}.callback{n1}{1},CONN_MM.MENU{n0}.callback{n1}{2:end});
CONN19.b
SPM12 + DAiSS DEM FieldMap MEEGtools
Matlab v.2019b
project: CONN19.b
--------------
Here is my current code. Do you know how I can edit it to work with CONN?
--------------
nsubjects = 2;
nsessions = 2;
nconditions = 7;
nses = 2; % 2 runs but need to concatenate to just one
conditions=cellstr(conn_dir('*_onsets_icontext_basic.mat')); % Load each subject's condition names, onsets, & durations file
for Con=1:length(nconditions)
for nsub = 1:nsubjects
load(conditions{nsub});
for nses = 1:nsessions
onsets_basic{nses,Con} = abs(onsets_basic{nses,Con});
batch.Setup.conditions.names{Con}=CondNames{Con};
batch.Setup.conditions.onsets{Con}{nsub}{nses}=onsets_basic;
batch.Setup.conditions.durations{Con}{nsub}{nses}=0;
end
end
end
--------------
Thanks so much for your quick reply! When I try to run the same code, but with two subjects with 2 sessions each, the GUI opens just fine, with both subjects added, but only 1 session gets added (with no onsets or durations) and I get a CONN error that reads:
--------------
ERROR DESCRIPTION:
Undefined function 'eq' for input arguments of type 'cell'.
Error in conn (line 3658)
if ~all(size(ko{1})==size(CONN_x.Setup.conditions.values{nsub}{ncondition}{nses}{1})) || ~all(all(ko{1}==CONN_x.Setup.conditions.values{nsub}{ncondition}{nses}{1})), ok(1)=0; end;
Error in conn (line 1499)
[varargout{1:nargout}]=conn('gui_setup',varargin{3:end});
Error in conn_menumanager (line 120)
feval(CONN_MM.MENU{n0}.callback{n1}{1},CONN_MM.MENU{n0}.callback{n1}{2:end});
CONN19.b
SPM12 + DAiSS DEM FieldMap MEEGtools
Matlab v.2019b
project: CONN19.b
--------------
Here is my current code. Do you know how I can edit it to work with CONN?
--------------
nsubjects = 2;
nsessions = 2;
nconditions = 7;
nses = 2; % 2 runs but need to concatenate to just one
conditions=cellstr(conn_dir('*_onsets_icontext_basic.mat')); % Load each subject's condition names, onsets, & durations file
for Con=1:length(nconditions)
for nsub = 1:nsubjects
load(conditions{nsub});
for nses = 1:nsessions
onsets_basic{nses,Con} = abs(onsets_basic{nses,Con});
batch.Setup.conditions.names{Con}=CondNames{Con};
batch.Setup.conditions.onsets{Con}{nsub}{nses}=onsets_basic;
batch.Setup.conditions.durations{Con}{nsub}{nses}=0;
end
end
end
--------------
Mar 28, 2020 12:03 PM | Alfonso Nieto-Castanon - Boston University
RE: Event-related conditions with batch
Hi Kaitlin,
perhaps try changing the line:
batch.Setup.conditions.onsets{Con}{nsub}{nses}=onsets_basic;
to:
batch.Setup.conditions.onsets{Con}{nsub}{nses}=onsets_basic{nses,Con};
Best
Alfonso
Originally posted by Kaitlin Cassady:
perhaps try changing the line:
batch.Setup.conditions.onsets{Con}{nsub}{nses}=onsets_basic;
to:
batch.Setup.conditions.onsets{Con}{nsub}{nses}=onsets_basic{nses,Con};
Best
Alfonso
Originally posted by Kaitlin Cassady:
Hi Alfonso,
Thanks so much for your quick reply! When I try to run the same code, but with two subjects with 2 sessions each, the GUI opens just fine, with both subjects added, but only 1 session gets added (with no onsets or durations) and I get a CONN error that reads:
--------------
ERROR DESCRIPTION:
Undefined function 'eq' for input arguments of type 'cell'.
Error in conn (line 3658)
if ~all(size(ko{1})==size(CONN_x.Setup.conditions.values{nsub}{ncondition}{nses}{1})) || ~all(all(ko{1}==CONN_x.Setup.conditions.values{nsub}{ncondition}{nses}{1})), ok(1)=0; end;
Error in conn (line 1499)
[varargout{1:nargout}]=conn('gui_setup',varargin{3:end});
Error in conn_menumanager (line 120)
feval(CONN_MM.MENU{n0}.callback{n1}{1},CONN_MM.MENU{n0}.callback{n1}{2:end});
CONN19.b
SPM12 + DAiSS DEM FieldMap MEEGtools
Matlab v.2019b
project: CONN19.b
--------------
Here is my current code. Do you know how I can edit it to work with CONN?
--------------
nsubjects = 2;
nsessions = 2;
nconditions = 7;
nses = 2; % 2 runs but need to concatenate to just one
conditions=cellstr(conn_dir('*_onsets_icontext_basic.mat')); % Load each subject's condition names, onsets, & durations file
for Con=1:length(nconditions)
for nsub = 1:nsubjects
load(conditions{nsub});
for nses = 1:nsessions
onsets_basic{nses,Con} = abs(onsets_basic{nses,Con});
batch.Setup.conditions.names{Con}=CondNames{Con};
batch.Setup.conditions.onsets{Con}{nsub}{nses}=onsets_basic;
batch.Setup.conditions.durations{Con}{nsub}{nses}=0;
end
end
end
--------------
Thanks so much for your quick reply! When I try to run the same code, but with two subjects with 2 sessions each, the GUI opens just fine, with both subjects added, but only 1 session gets added (with no onsets or durations) and I get a CONN error that reads:
--------------
ERROR DESCRIPTION:
Undefined function 'eq' for input arguments of type 'cell'.
Error in conn (line 3658)
if ~all(size(ko{1})==size(CONN_x.Setup.conditions.values{nsub}{ncondition}{nses}{1})) || ~all(all(ko{1}==CONN_x.Setup.conditions.values{nsub}{ncondition}{nses}{1})), ok(1)=0; end;
Error in conn (line 1499)
[varargout{1:nargout}]=conn('gui_setup',varargin{3:end});
Error in conn_menumanager (line 120)
feval(CONN_MM.MENU{n0}.callback{n1}{1},CONN_MM.MENU{n0}.callback{n1}{2:end});
CONN19.b
SPM12 + DAiSS DEM FieldMap MEEGtools
Matlab v.2019b
project: CONN19.b
--------------
Here is my current code. Do you know how I can edit it to work with CONN?
--------------
nsubjects = 2;
nsessions = 2;
nconditions = 7;
nses = 2; % 2 runs but need to concatenate to just one
conditions=cellstr(conn_dir('*_onsets_icontext_basic.mat')); % Load each subject's condition names, onsets, & durations file
for Con=1:length(nconditions)
for nsub = 1:nsubjects
load(conditions{nsub});
for nses = 1:nsessions
onsets_basic{nses,Con} = abs(onsets_basic{nses,Con});
batch.Setup.conditions.names{Con}=CondNames{Con};
batch.Setup.conditions.onsets{Con}{nsub}{nses}=onsets_basic;
batch.Setup.conditions.durations{Con}{nsub}{nses}=0;
end
end
end
--------------
Mar 28, 2020 08:03 PM | Kaitlin Cassady - University of Michigan - Ann Arbor
RE: Event-related conditions with batch
Hi Alfonso,
Thanks! This loaded in the first session for the first condition for both subjects! However, for some reason, it's not adding in all 7 conditions (only 1) and it's not adding in the second session. I'm attaching one subject's condition/onset .mat file for your reference (I'm not able to attach both subjects' data, only one). Do you know what the problem might be?
Thank you!
Thanks! This loaded in the first session for the first condition for both subjects! However, for some reason, it's not adding in all 7 conditions (only 1) and it's not adding in the second session. I'm attaching one subject's condition/onset .mat file for your reference (I'm not able to attach both subjects' data, only one). Do you know what the problem might be?
Thank you!
Apr 5, 2020 12:04 AM | Alfonso Nieto-Castanon - Boston University
RE: Event-related conditions with batch
Hi Kaitlin,
Yes, the 1-contrast-only issue should be fixed by changing the line:
for Con=1:length(nconditions)
to:
for Con=1:nconditions
The 1-sesssion-only issue may be caused by not yet having defined/entered the functional data in your project. Sorry CONN expects you to enter the functional data before defining the condition information (mainly because the functional data is used to derive the number of sessions for each subject in your dataset, as well as the session length for each subject/session, which are needed to properly interpret your onset/duration information). If that is the case, simply using batch.Setup.functionals to define your functional data (either ini this same batch, or before running this batch) should fix this issue.
Best
Alfonso
Originally posted by Kaitlin Cassady:
Yes, the 1-contrast-only issue should be fixed by changing the line:
for Con=1:length(nconditions)
to:
for Con=1:nconditions
The 1-sesssion-only issue may be caused by not yet having defined/entered the functional data in your project. Sorry CONN expects you to enter the functional data before defining the condition information (mainly because the functional data is used to derive the number of sessions for each subject in your dataset, as well as the session length for each subject/session, which are needed to properly interpret your onset/duration information). If that is the case, simply using batch.Setup.functionals to define your functional data (either ini this same batch, or before running this batch) should fix this issue.
Best
Alfonso
Originally posted by Kaitlin Cassady:
Hi Alfonso,
Thanks! This loaded in the first session for the first condition for both subjects! However, for some reason, it's not adding in all 7 conditions (only 1) and it's not adding in the second session. I'm attaching one subject's condition/onset .mat file for your reference (I'm not able to attach both subjects' data, only one). Do you know what the problem might be?
Thank you!
Thanks! This loaded in the first session for the first condition for both subjects! However, for some reason, it's not adding in all 7 conditions (only 1) and it's not adding in the second session. I'm attaching one subject's condition/onset .mat file for your reference (I'm not able to attach both subjects' data, only one). Do you know what the problem might be?
Thank you!
Apr 7, 2020 02:04 AM | Kaitlin Cassady - University of Michigan - Ann Arbor
RE: Event-related conditions with batch
Thanks, Alfonso!
When I tried changing the number of functionals for each subject (2 sessions for each of 2 subjects), I get the folllowing error:
functionalz=cellstr(conn_dir('4D_uaf*.nii'));
batch.Setup.functionals=repmat({{}},[nsubjects,1]);
for nsub=1:nsubjects
for nses=1:nsessions
batch.Setup.functionals{nsub}{nses}=functionalz{nsub,nses};
end
end
"Index in position 2 exceeds array bounds (must not exceed 1)." I think this is a really easy fix, but I'm not sure what it is. Do you know?
Thanks!
Kaitlin
When I tried changing the number of functionals for each subject (2 sessions for each of 2 subjects), I get the folllowing error:
functionalz=cellstr(conn_dir('4D_uaf*.nii'));
batch.Setup.functionals=repmat({{}},[nsubjects,1]);
for nsub=1:nsubjects
for nses=1:nsessions
batch.Setup.functionals{nsub}{nses}=functionalz{nsub,nses};
end
end
"Index in position 2 exceeds array bounds (must not exceed 1)." I think this is a really easy fix, but I'm not sure what it is. Do you know?
Thanks!
Kaitlin
Apr 8, 2020 07:04 PM | Kaitlin Cassady - University of Michigan - Ann Arbor
RE: Event-related conditions with batch
Hi Alfonso,
Never mind, I figured it out! I changed the code to:
functionalz=cellstr(conn_dir('4D_uaf*.nii'));
functionalz=reshape(functionalz,[nsessions,nsubjects]);
batch.Setup.functionals=repmat({{}},[nsubjects,1]);
for nsub=1:nsubjects
for nses=1:nsessions
batch.Setup.functionals{nsub}{nses}=functionalz{nses,nsub};
end
end
... and it worked. Thanks for all your help! :)
Never mind, I figured it out! I changed the code to:
functionalz=cellstr(conn_dir('4D_uaf*.nii'));
functionalz=reshape(functionalz,[nsessions,nsubjects]);
batch.Setup.functionals=repmat({{}},[nsubjects,1]);
for nsub=1:nsubjects
for nses=1:nsessions
batch.Setup.functionals{nsub}{nses}=functionalz{nses,nsub};
end
end
... and it worked. Thanks for all your help! :)