-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjpa_addTContrast.m
More file actions
90 lines (83 loc) · 2.39 KB
/
jpa_addTContrast.m
File metadata and controls
90 lines (83 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function matlabbatch = jpa_addTContrast(batch, nameOfTcon, weights, varargin)
% Function that adds a TContrast to a SPM Contrast Manager-Module
%
% Syntax:
% batch = jpa_addTContrast(batch, nameOfTcon, weights)
% batch = jpa_addTContrast(batch, nameOfTcon, weights, sessrep)
%
% Inputs:
% batch - SPM-Struct which contains Module Contrast Manager
% nameOfTcon - Name of new TContrast
% weights - Weights of new TContrast
% sessrep - String containing Information about Session Replication
%
% Outputs:
% matlabbatch - SPM-Struct with all Modules it had before and
% the new TContrast in SPM Contrast Manager Module
%
% Example:
% batch = jpa_addTContrast(matlabbatch, 'name1', [1 1], 'none')
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also: jpa_initialConMan
% Author: Jan Albrecht
% Work address:
% email: jan-philipp.albrecht@charite.de, j.p.albrecht@fu-berlin.de
% Website:
% Sep 2015; Last revision: 29-Sep-2015
%------------- BEGIN CODE --------------
%% test for mistakes
if nargin < 3
error('Number of Input-Arguments not correct!');
end
if ~ischar(nameOfTcon)
error('Input Argument "nameOfTcon" not correct!');
end
if ~isvector(weights)
error('Input Argument "weight" not correct!');
end
if nargin == 3
sessrep = 'none';
else
sessrep = varargin{1};
end
%% Initialisierung
matlabbatch = batch;
% determine size
[l, m] = size(matlabbatch);
% check wich level is con-manager
conmanNum = 0;
for i=1:1:m
% check for Structure
if isfield(matlabbatch{1,i}, 'spm')
% check for stats field
if isfield(matlabbatch{1,i}.spm, 'stats')
% check for con field
if isfield(matlabbatch{1,i}.spm.stats, 'con')
% load structures in conman
conman = matlabbatch{1,i}.spm.stats.con;
conmanNum = i;
end
end
end
end
% end of loop, conman not found
if i == m && conmanNum == 0
error('Batch does not contain Module Contrast-Manager')
end
%% add Contrast
% check for contrasts
[l, j] = size(conman.consess);
% design new tcon
c.tcon.name = nameOfTcon;
c.tcon.weights = weights;
c.tcon.sessrep = sessrep;
% add a contrast at position j+1 to not delete anything
conman.consess{1,(j+1)} = c;
% include in batch
matlabbatch{1,conmanNum}.spm.stats.con = conman;
end
%------------- END CODE --------------