|
14 | 14 | % SPM style onsets file with one event type, or (3) an epochs file |
15 | 15 | % (see pspm_dcm or pspm_get_epochs). |
16 | 16 | % * outfile : (optional) a file to write the response function to |
17 | | -% * channel : (optional) data channel (default: look for first SCR channel) |
| 17 | +% * channel : (optional) data channel (default: look for first SCR channel) |
18 | 18 | % * options : [struct] to be passed on to pspm_dcm |
19 | 19 | % ● History |
20 | 20 | % Introduced in PsPM 3.0 |
21 | 21 | % Written in 2008-2015 by Dominik R Bach (Wellcome Trust Centre for Neuroimaging) |
| 22 | +% Updated in 2026 by Bernhard A. von Raußendorf |
22 | 23 |
|
23 | 24 | %% initialise |
24 | 25 | global settings |
25 | 26 | if isempty(settings) |
26 | 27 | pspm_init; |
27 | 28 | end |
28 | 29 | sts = -1; |
29 | | -rf = []; |
| 30 | +rf = []; % in the m-function can be removed |
| 31 | +theta = []; |
30 | 32 |
|
31 | 33 | %% check input |
32 | 34 | if nargin < 1 |
|
40 | 42 | [pth infn ext] = fileparts(fn); |
41 | 43 | outfile = fullfile(pth, ['RF_', infn, ext]); |
42 | 44 | end |
43 | | -if nargin < 4 |
| 45 | +if nargin < 4 || isempty(channel) |
44 | 46 | channel = 'scr'; |
45 | 47 | end |
| 48 | +if nargin < 5 || isempty(options) |
| 49 | + options = struct(); |
| 50 | +end |
| 51 | + |
46 | 52 |
|
47 | 53 | %% call DCM |
48 | 54 | options = pspm_options(options, 'get_rf'); |
49 | 55 | % options.getrf = 1; |
50 | 56 | %try options.nosave, catch, options.nosave = 1; end |
51 | | -options.channel = channel; |
52 | | -[foo dcm] = pspm_dcm(fn, '', events, options); |
53 | | -if numel(dcm{1}.prior.posterior) == 2 |
| 57 | +if options.invalid |
| 58 | + warning('options invalid') % change! |
| 59 | + return; |
| 60 | +end |
| 61 | + |
| 62 | +% prepare timing for pspm_dcm -> maybe change! |
| 63 | +if isnumeric(events) |
| 64 | + if isvector(events) |
| 65 | + events = {events(:)}; |
| 66 | + else |
| 67 | + events = {events}; |
| 68 | + end |
| 69 | +end |
| 70 | + |
| 71 | +model.datafile = {fn}; |
| 72 | +model.timing = {events}; |
| 73 | +model.channel = channel; |
| 74 | +model.modelfile = [tempname, '.mat']; |
| 75 | + |
| 76 | +[dsts, dcm] = pspm_dcm(model, options); |
| 77 | +if dsts < 1 || isempty(dcm) |
| 78 | + warning('RF estimation failed in pspm_dcm.'); % change! |
| 79 | + return; |
| 80 | +end |
| 81 | + |
| 82 | +% options.channel = channel; |
| 83 | +% [foo dcm] = pspm_dcm(fn, '', events, options); |
| 84 | + |
| 85 | + |
| 86 | +if iscell(dcm) |
| 87 | + dcm_rf = dcm{1}; |
| 88 | +else |
| 89 | + dcm_rf = dcm; |
| 90 | +end |
| 91 | + |
| 92 | +if numel(dcm_rf.prior.posterior) == 2 |
54 | 93 | % based on eSCR |
55 | | - theta = dcm{1}.prior.posterior(2).muTheta(1:7)'; |
| 94 | + theta = dcm_rf.prior.posterior(2).muTheta(1:7)'; |
56 | 95 | else |
57 | 96 | % based on aSCR (i. e. updated RF) |
58 | | - theta = dcm{1}.prior.posterior(3).muTheta(1:7)'; |
| 97 | + theta = dcm_rf.prior.posterior(3).muTheta(1:7)'; |
59 | 98 | end |
60 | 99 |
|
| 100 | +% if numel(dcm{1}.prior.posterior) == 2 |
| 101 | +% % based on eSCR |
| 102 | +% theta = dcm{1}.prior.posterior(2).muTheta(1:7)'; |
| 103 | +% else |
| 104 | +% % based on aSCR (i. e. updated RF) |
| 105 | +% theta = dcm{1}.prior.posterior(3).muTheta(1:7)'; |
| 106 | +% end |
| 107 | + |
61 | 108 | %% write response function to file |
62 | | -if ~isempty(outfile) |
| 109 | +if ~isempty(outfile) % should never be empty! |
63 | 110 | [pth fn ext] = fileparts(outfile); |
64 | | - c = clock; |
| 111 | + c = clock; % timestamp |
65 | 112 | job{1} = sprintf('function [rf, theta] = %s(td)', fn); |
66 | 113 | job{2} = '%-----------------------------------------------------------------------'; |
67 | 114 | job{3} = ['% Response function created by pspm_get_rf, ', date, sprintf(' %02.0f:%02.0f', c(4:5))]; |
|
82 | 129 | job{18} = sprintf('rf = Xt(1, :);'); |
83 | 130 | job{19} = sprintf('rf = rf/max(rf);'); |
84 | 131 | job{20} = sprintf('rf = rf(:);'); |
85 | | - job = strvcat(job'); |
| 132 | + % job = strvcat(job'); |
| 133 | + % outfile = fullfile(pth, [fn, '.m']); |
| 134 | + % dlmwrite(outfile, job, 'delimiter', ''); |
86 | 135 | outfile = fullfile(pth, [fn, '.m']); |
87 | | - dlmwrite(outfile, job, 'delimiter', ''); |
| 136 | + |
| 137 | + fid = fopen(outfile, 'w'); |
| 138 | + fprintf(fid, '%s\n', job{:}); |
| 139 | + fclose(fid); |
88 | 140 | end |
| 141 | + |
89 | 142 | sts = 1; |
90 | 143 | return |
| 144 | + |
| 145 | +end |
0 commit comments