Skip to content

Commit fcc9f6f

Browse files
committed
Fix formatting and update model filename handling
1 parent 1409fda commit fcc9f6f

1 file changed

Lines changed: 30 additions & 25 deletions

File tree

src/pspm_pipeline_fc_scr.m

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
% PSPM_PIPELINE_FC_SCR Run PsPM DCM pipeline for fear-conditioned SCR
33
%
44
% ● Description
5-
% Runs a standard PsPM pipeline for fear-conditioned skin conductance
6-
% responses (SCR), based on the methods described in:
5+
% Runs a standard PsPM pipeline for fear-conditioned skin conductance
6+
% responses (SCR), based on the methods described in:
77
% de Vries et al. (2026, in preparation).
88
%
9-
% The function supports single or multiple sessions/files. All inputs are
10-
% internally normalised to cell arrays and processed per session.
9+
% The function supports single or multiple sessions/files. All inputs are
10+
% internally normalised to cell arrays and processed per session.
1111
%
12-
%Syntax
12+
%Format
1313
% [sts, out] = pspm_pipeline_fc_scr(fn, onsets, isi);
1414
% - Uses default method: '2026_long_uni'
1515
% - No missing data
@@ -38,18 +38,18 @@
3838
% - Save model file to disk
3939
% - Overwrite existing model files if present
4040
%
41-
%Inputs
42-
% fn - PsPM data file (string/char) or cell array of files
41+
%Arguments
42+
% * fn: - PsPM data file (string/char) or cell array of files
4343
%
44-
% onsets - CS onset times (in seconds)
44+
% * onsets: - CS onset times (in seconds)
4545
% • numeric vector, or cell array of vectors (one per session)
4646
%
47-
% isi - CS–US interval (in seconds)
47+
% * isi: - CS–US interval (in seconds)
4848
% • scalar (applied to all trials)
4949
% • vector (same length as onsets per session)
5050
% • or cell array (one entry per session)
5151
%
52-
% method - (optional) Processing method (string)
52+
% * method: - (optional) Processing method (string)
5353
% Default: '2026_long_uni'
5454
% • '2026_short'
5555
% • '2026_long_uni'
@@ -59,24 +59,24 @@
5959
% - 'short' vs 'long' refers to ISI regime
6060
% - 'uni' / 'bi' refers to filter direction
6161
%
62-
% missing - (optional) Missing/artefact epochs file(s), or []
62+
% * missing: - (optional) Missing/artefact epochs file(s), or []
6363
% • string/char, cell array, or []
6464
% • if empty, no missing data are applied
6565
%
66-
% normalize - (optional) logical or 0/1
66+
% * normalize:- (optional) logical or 0/1
6767
% Normalize data during inversion (default: 0)
6868
%
69-
% keepfile - (optional) logical or 0/1
69+
% * keepfile: - (optional) logical or 0/1
7070
% Save model file to disk (default: 0)
7171
%
72-
% overwrite - (optional) logical or 0/1
72+
% * overwrite:- (optional) logical or 0/1
7373
% Overwrite existing model files (default: 0)
7474
%
7575
% ● Outputs
76-
% sts - Status flag returned by pspm_dcm
76+
% * sts: - Status flag returned by pspm_dcm
7777
% > 0 indicates success
7878
%
79-
% out - Trial-wise conditioned response estimates
79+
% * out: - Trial-wise conditioned response estimates
8080
% • short ISI: amplitude estimates
8181
% • long ISI: combined amplitude × dispersion estimates
8282
%
@@ -104,11 +104,11 @@
104104

105105
% set default args
106106
p = inputParser;
107-
addParameter(p, 'method', '2026_long_uni');
108-
addParameter(p, 'missing', []);
109-
addParameter(p, 'normalize', 0);
110-
addParameter(p, 'keepfile', 0);
111-
addParameter(p, 'overwrite', 0);
107+
addParameter(p, 'method', '2026_long_uni', @(x) ischar(x) );
108+
addParameter(p, 'missing', [], @(x) isempty(x) || ischar(x) || iscell(x));
109+
addParameter(p, 'normalize', 0, @(x) (islogical(x) || isnumeric(x)) && isscalar(x) && ismember(x, [0 1]));
110+
addParameter(p, 'keepfile', 0, @(x) (islogical(x) || isnumeric(x)) && isscalar(x) && ismember(x, [0 1]));
111+
addParameter(p, 'overwrite', 0, @(x) (islogical(x) || isnumeric(x)) && isscalar(x) && ismember(x, [0 1]));
112112
parse(p, varargin{:});
113113

114114
method = p.Results.method;
@@ -176,9 +176,11 @@
176176
timing{i_sn}{1} = this_onsets + this_isi;
177177

178178
if strcmpi(method, '2026_short')
179+
% flex-fix
179180
timing{i_sn}{2} = [this_onsets, this_onsets + this_isi];
180181

181182
elseif ismember(method, {'2026_long_uni', '2026_long_bi'})
183+
% flex-flex-fix with halved ISI
182184
timing{i_sn}{2} = [this_onsets, this_onsets + this_isi/2];
183185
timing{i_sn}{3} = [this_onsets + this_isi/2, this_onsets + this_isi];
184186

@@ -189,11 +191,13 @@
189191

190192
%% Setup model
191193
% set (dummy) filename
192-
model_fn = cell(size(fn));
194+
% One DCM model file for all sessions together
195+
[pth_i, fn_m_i, ~] = fileparts(fn{1});
193196

194-
for i = 1:numel(fn)
195-
[pth_i, fn_m_i, ~] = fileparts(fn{i});
196-
model_fn{i} = fullfile(pth_i, ['mdl1_', fn_m_i, '.mat']);
197+
if numel(fn) == 1
198+
model_fn = fullfile(pth_i, ['mdl1_', fn_m_i, '.mat']);
199+
else
200+
model_fn = fullfile(pth_i, ['mdl1_', fn_m_i, '_multi.mat']);
197201
end
198202

199203
model = struct( ...
@@ -241,4 +245,5 @@
241245
out = dcm.stats(:, amp_indx(1)) .* dcm.stats(:, disp_indx(1)) + ... % a x c for each response, then summed
242246
dcm.stats(:, amp_indx(2)) .* dcm.stats(:, disp_indx(2));
243247
end
248+
end
244249
end

0 commit comments

Comments
 (0)