This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
forked from Washington-University/cifti-matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cifti_create_pconn_from_template.m
39 lines (39 loc) · 1.93 KB
/
cifti_create_pconn_from_template.m
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
function cifti = cifti_create_pconn_from_template(ciftitemplate, data, varargin)
%function cifti = cifti_create_pconn_from_template(ciftitemplate, data, ...)
% Create a square pconn from any parcels file and a square data matrix.
% Non-square pconns must be made manually by setting cifti.diminfo and cifti.cdata.
%
% If the template cifti file has more than one parcels dimension (such as pconn),
% you must use "..., 'dimension', 1" or similar to select the dimension to copy the
% parcels mapping from.
options = myargparse(varargin, {'dimension'});
if length(size(data)) ~= 2
error('input data must be a 2D matrix');
end
if size(data, 1) ~= size(data, 2)
error('this function is only for making a square pconn from a pscalar or similar template, asymmetric pconns must be made manually by setting cifti.cdata to the new matrix');
end
if isempty(options.dimension)
options.dimension = [];
for i = 1:length(ciftitemplate.diminfo)
if strcmp(ciftitemplate.diminfo{i}.type, 'parcels')
options.dimension = [options.dimension i]; %#ok<AGROW>
end
end
if isempty(options.dimension)
error('template cifti has no parcels dimension');
end
if ~isscalar(options.dimension)
error('template cifti has more than one parcels dimension, you must specify the dimension to use');
end
end
if ~strcmp(ciftitemplate.diminfo{options.dimension}.type, 'parcels')
error('selected dimension of template cifti file is not of type parcels');
end
if size(data, 1) ~= ciftitemplate.diminfo{options.dimension}.length
error('input data has the wrong dimensions for the parcels diminfo');
end
cifti.cdata = data;
cifti.metadata = ciftitemplate.metadata;
cifti.diminfo = {ciftitemplate.diminfo{options.dimension} ciftitemplate.diminfo{options.dimension}};
end