\n');
+ fprintf(fid,'%s\n',o(4));
+ fprintf(fid,'%s\n',o(3));
+ fprintf(fid,'%s\n',o(2));
+end
+fprintf(fid,'%s\n',o(1));
+
+% Scene
+%--------------------------------------------------------------------------
+fprintf(fid,'%s\n',o(1));
+fprintf(fid,'%s\n',o(2));
+for i=1:numel(s)
+ fprintf(fid,'%s\n',o(3),i);
+ fprintf(fid,'%s\n',o(4),i);
+ fprintf(fid,'%s\n',o(5));
+ fprintf(fid,'%s\n',o(6));
+ fprintf(fid,'%s\n',o(7),i,i);
+ fprintf(fid,'%s\n',o(6));
+ fprintf(fid,'%s\n',o(5));
+ fprintf(fid,'%s\n',o(4));
+ fprintf(fid,'%s\n',o(3));
+end
+fprintf(fid,'%s\n',o(2));
+fprintf(fid,'%s\n',o(1));
+fprintf(fid,'%s\n',o(1));
+fprintf(fid,'%s\n',o(2));
+fprintf(fid,'%s\n',o(1));
+
+% End of XML
+%--------------------------------------------------------------------------
+fprintf(fid,'\n');
+
+% Close file
+%--------------------------------------------------------------------------
+fclose(fid);
+
+
+%==========================================================================
+% function save_idtf(s,filename)
+%==========================================================================
+function save_idtf(s,filename)
+
+o = @(x) blanks(x*3);
+
+% Compute normals
+%--------------------------------------------------------------------------
+if ~isfield(s,'normals')
+ try
+ s.normals = spm_mesh_normals(...
+ struct('vertices',s.vertices,'faces',s.faces),true);
+ catch
+ s.normals = [];
+ end
+end
+
+% Split the mesh into connected components
+%--------------------------------------------------------------------------
+try
+ C = spm_mesh_label(s.faces);
+ d = [];
+ try
+ if size(s.cdata,2) == 1 && (any(s.cdata>1) || any(s.cdata<0))
+ mi = min(s.cdata); ma = max(s.cdata);
+ s.cdata = (s.cdata-mi)/ (ma-mi);
+ else
+ end
+ end
+ for i=1:numel(unique(C))
+ d(i).faces = s.faces(C==i,:);
+ u = unique(d(i).faces);
+ d(i).vertices = s.vertices(u,:);
+ d(i).normals = s.normals(u,:);
+ a = 1:max(d(i).faces(:));
+ a(u) = 1:size(d(i).vertices,1);
+ %a = sparse(1,double(u),1:1:size(d(i).vertices,1));
+ d(i).faces = a(d(i).faces);
+ d(i).mat = s.mat;
+ try
+ d(i).cdata = s.cdata(u,:);
+ if size(d(i).cdata,2) == 1
+ d(i).cdata = repmat(d(i).cdata,1,3);
+ end
+ end
+ end
+ s = d;
+end
+
+% Open file for writing
+%--------------------------------------------------------------------------
+fid = fopen(filename,'wt');
+if fid == -1
+ error('Unable to write file %s: permission denied.',filename);
+end
+
+% FILE_HEADER
+%--------------------------------------------------------------------------
+fprintf(fid,'FILE_FORMAT "IDTF"\n');
+fprintf(fid,'FORMAT_VERSION 100\n\n');
+
+% NODES
+%--------------------------------------------------------------------------
+for i=1:numel(s)
+ fprintf(fid,'NODE "MODEL" {\n');
+ fprintf(fid,'%sNODE_NAME "%s"\n',o(1),sprintf('Mesh%04d',i));
+ fprintf(fid,'%sPARENT_LIST {\n',o(1));
+ fprintf(fid,'%sPARENT_COUNT %d\n',o(2),1);
+ fprintf(fid,'%sPARENT %d {\n',o(2),0);
+ fprintf(fid,'%sPARENT_NAME "%s"\n',o(3),'');
+ fprintf(fid,'%sPARENT_TM {\n',o(3));
+ I = s(i).mat; % eye(4);
+ for j=1:size(I,2)
+ fprintf(fid,'%s',o(4)); fprintf(fid,'%f ',I(:,j)'); fprintf(fid,'\n');
+ end
+ fprintf(fid,'%s}\n',o(3));
+ fprintf(fid,'%s}\n',o(2));
+ fprintf(fid,'%s}\n',o(1));
+ fprintf(fid,'%sRESOURCE_NAME "%s"\n',o(1),sprintf('Mesh%04d',i));
+ %fprintf(fid,'%sMODEL_VISIBILITY "BOTH"\n',o(1));
+ fprintf(fid,'}\n\n');
+end
+
+% NODE_RESOURCES
+%--------------------------------------------------------------------------
+for i=1:numel(s)
+ fprintf(fid,'RESOURCE_LIST "MODEL" {\n');
+ fprintf(fid,'%sRESOURCE_COUNT %d\n',o(1),1);
+ fprintf(fid,'%sRESOURCE %d {\n',o(1),0);
+ fprintf(fid,'%sRESOURCE_NAME "%s"\n',o(2),sprintf('Mesh%04d',i));
+ fprintf(fid,'%sMODEL_TYPE "MESH"\n',o(2));
+ fprintf(fid,'%sMESH {\n',o(2));
+ fprintf(fid,'%sFACE_COUNT %d\n',o(3),size(s(i).faces,1));
+ fprintf(fid,'%sMODEL_POSITION_COUNT %d\n',o(3),size(s(i).vertices,1));
+ fprintf(fid,'%sMODEL_NORMAL_COUNT %d\n',o(3),size(s(i).normals,1));
+ if ~isfield(s(i),'cdata') || isempty(s(i).cdata)
+ c = 0;
+ else
+ c = size(s(i).cdata,1);
+ end
+ fprintf(fid,'%sMODEL_DIFFUSE_COLOR_COUNT %d\n',o(3),c);
+ fprintf(fid,'%sMODEL_SPECULAR_COLOR_COUNT %d\n',o(3),0);
+ fprintf(fid,'%sMODEL_TEXTURE_COORD_COUNT %d\n',o(3),0);
+ fprintf(fid,'%sMODEL_BONE_COUNT %d\n',o(3),0);
+ fprintf(fid,'%sMODEL_SHADING_COUNT %d\n',o(3),1);
+ fprintf(fid,'%sMODEL_SHADING_DESCRIPTION_LIST {\n',o(3));
+ fprintf(fid,'%sSHADING_DESCRIPTION %d {\n',o(4),0);
+ fprintf(fid,'%sTEXTURE_LAYER_COUNT %d\n',o(5),0);
+ fprintf(fid,'%sSHADER_ID %d\n',o(5),0);
+ fprintf(fid,'%s}\n',o(4));
+ fprintf(fid,'%s}\n',o(3));
+
+ fprintf(fid,'%sMESH_FACE_POSITION_LIST {\n',o(3));
+ fprintf(fid,'%d %d %d\n',s(i).faces'-1);
+ fprintf(fid,'%s}\n',o(3));
+
+ fprintf(fid,'%sMESH_FACE_NORMAL_LIST {\n',o(3));
+ fprintf(fid,'%d %d %d\n',s(i).faces'-1);
+ fprintf(fid,'%s}\n',o(3));
+
+ fprintf(fid,'%sMESH_FACE_SHADING_LIST {\n',o(3));
+ fprintf(fid,'%d\n',zeros(size(s(i).faces,1),1));
+ fprintf(fid,'%s}\n',o(3));
+
+ if c
+ fprintf(fid,'%sMESH_FACE_DIFFUSE_COLOR_LIST {\n',o(3));
+ fprintf(fid,'%d %d %d\n',s(i).faces'-1);
+ fprintf(fid,'%s}\n',o(3));
+ end
+
+ fprintf(fid,'%sMODEL_POSITION_LIST {\n',o(3));
+ fprintf(fid,'%f %f %f\n',s(i).vertices');
+ fprintf(fid,'%s}\n',o(3));
+
+ fprintf(fid,'%sMODEL_NORMAL_LIST {\n',o(3));
+ fprintf(fid,'%f %f %f\n',s(i).normals');
+ fprintf(fid,'%s}\n',o(3));
+
+ if c
+ fprintf(fid,'%sMODEL_DIFFUSE_COLOR_LIST {\n',o(3));
+ fprintf(fid,'%f %f %f\n',s(i).cdata');
+ fprintf(fid,'%s}\n',o(3));
+ end
+
+ fprintf(fid,'%s}\n',o(2));
+ fprintf(fid,'%s}\n',o(1));
+ fprintf(fid,'}\n');
+end
+
+% Close file
+%--------------------------------------------------------------------------
+fclose(fid);
diff --git a/@gifti/struct.m b/@gifti/struct.m
index 3272e368..98f97c93 100644
--- a/@gifti/struct.m
+++ b/@gifti/struct.m
@@ -7,13 +7,12 @@
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
% Guillaume Flandin
-% $Id: struct.m 4716 2012-04-19 11:01:32Z guillaume $
+% $Id: struct.m 6507 2015-07-24 16:48:02Z guillaume $
names = fieldnames(this);
-names = unique(names);
values = cell(length(names), length(this(:)));
for i=1:length(names)
[values{i,:}] = subsref(this(:), substruct('.',names{i}));
end
-s = reshape(cell2struct(values,names,1),size(this));
\ No newline at end of file
+s = reshape(cell2struct(values,names,1),size(this));
diff --git a/@gifti/subsasgn.m b/@gifti/subsasgn.m
index 097f5c74..3b3f7695 100644
--- a/@gifti/subsasgn.m
+++ b/@gifti/subsasgn.m
@@ -4,108 +4,134 @@
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
% Guillaume Flandin
-% $Id: subsasgn.m 6416 2015-04-21 15:34:10Z guillaume $
+% $Id: subsasgn.m 6513 2015-08-05 17:52:13Z guillaume $
switch subs(1).type
case '.'
- if ~ismember(subs(1).subs, {'vertices' 'faces' 'normals' 'cdata','mat','indices','private'})
+ if ~ismember(subs(1).subs, ...
+ {'vertices' 'faces' 'normals' 'cdata','mat','indices','private'})
error('Reference to non-existent field ''%s''.',subs(1).subs);
- else
- % TODO % handle cases when length(subs) > 1
- [i,n] = isintent(this,subs(1).subs);
- if isempty(i) && ~strcmp(subs(1).subs,'private')
- n = length(this.data) + 1;
- if n==1, this.data = {};end
- % TODO % Initialise data field appropriately
- this.data{n}.metadata = struct([]);
- this.data{n}.space = [];
- this.data{n}.attributes.Dim = size(A);
- % TODO % set DataType according to intent type
- this.data{n}.data = [];
- switch subs(1).subs
- case {'vertices','mat'}
- in = 'NIFTI_INTENT_POINTSET';
- dt = 'NIFTI_TYPE_FLOAT32';
- this.data{n}.space.DataSpace = 'NIFTI_XFORM_UNKNOWN';
- this.data{n}.space.TransformedSpace = 'NIFTI_XFORM_UNKNOWN';
- this.data{n}.space.MatrixData = eye(4);
- case 'faces'
- in = 'NIFTI_INTENT_TRIANGLE';
- dt = 'NIFTI_TYPE_INT32';
- case 'indices'
- in = 'NIFTI_INTENT_NODE_INDEX';
- dt = 'NIFTI_TYPE_INT32';
- case 'normals'
- in = 'NIFTI_INTENT_VECTOR';
- dt = 'NIFTI_TYPE_FLOAT32';
- case 'cdata'
- in = 'NIFTI_INTENT_NONE';
- dt = 'NIFTI_TYPE_FLOAT32';
- otherwise
- error('This should not happen.');
- end
- this.data{n}.attributes.Intent = in;
- this.data{n}.attributes.DataType = dt;
+ end
+ % TODO % handle cases when length(subs) > 1
+ [i,n] = isintent(this,subs(1).subs);
+ if isempty(i) && ~strcmp(subs(1).subs,'private')
+ n = length(this.data) + 1;
+ if n==1, this.data = {}; end
+ % TODO % Initialise data field appropriately
+ this.data{n}.metadata = struct([]);
+ this.data{n}.space = [];
+ this.data{n}.attributes.Dim = size(A);
+ % TODO % set DataType according to intent type
+ this.data{n}.data = [];
+ switch subs(1).subs
+ case {'vertices','mat'}
+ in = 'NIFTI_INTENT_POINTSET';
+ dt = 'NIFTI_TYPE_FLOAT32';
+ this.data{n}.space.DataSpace = 'NIFTI_XFORM_UNKNOWN';
+ this.data{n}.space.TransformedSpace = 'NIFTI_XFORM_UNKNOWN';
+ this.data{n}.space.MatrixData = eye(4);
+ case 'faces'
+ in = 'NIFTI_INTENT_TRIANGLE';
+ dt = 'NIFTI_TYPE_INT32';
+ case 'indices'
+ in = 'NIFTI_INTENT_NODE_INDEX';
+ dt = 'NIFTI_TYPE_INT32';
+ case 'normals'
+ in = 'NIFTI_INTENT_VECTOR';
+ dt = 'NIFTI_TYPE_FLOAT32';
+ case 'cdata'
+ in = 'NIFTI_INTENT_NONE';
+ dt = 'NIFTI_TYPE_FLOAT32';
+ otherwise
+ error('This should not happen.');
end
- if strcmp(subs(1).subs,'mat')
+ this.data{n}.attributes.Intent = in;
+ this.data{n}.attributes.DataType = dt;
+ end
+
+ switch subs(1).subs
+ %- .private
+ %--------------------------------------------------------------
+ case 'private'
+ this = builtin('subsasgn',this,subs(2:end),A);
+
+ % .mat
+ %--------------------------------------------------------------
+ case 'mat'
if length(subs) > 1
this.data{n}.space(1).MatrixData = builtin('subsasgn',...
this.data{n}.space(1).MatrixData,subs(2:end),A);
else
- if ndims(A) ~= 2 || any(size(A) ~= [4 4])
+ if ~isequal(size(A),[4 4])
error('Invalid Coordinate System Transform Matrix.');
- else
- this.data{n}.space(1).MatrixData = A;
end
+ this.data{n}.space(1).MatrixData = A;
end
- elseif strcmp(subs(1).subs,'private')
- this = builtin('subsasgn',this,subs(2:end),A);
- else
- if strcmp(subs(1).subs,'faces') || strcmp(subs(1).subs,'indices')
- if length(subs) > 1
- this.data{n}.data = int32(builtin('subsasgn',this.data{n}.data,subs(2:end),A-1));
- else
- this.data{n}.data = int32(A - 1);
- this.data{n}.attributes.Dim = size(A);
- end
+
+ %- .faces
+ %--------------------------------------------------------------
+ case 'faces'
+ if length(subs) > 1
+ this.data{n}.data = int32(builtin('subsasgn',this.data{n}.data,subs(2:end),A-1));
else
- if length(subs) > 1
- if numel(n) == 1
- this.data{n}.data = single(builtin('subsasgn',this.data{n}.data,subs(2:end),A));
- this.data{n}.attributes.Dim = size(this.data{n}.data);
- else
- if numel(subs(2).subs) == 1
- error('Linear indexing not supported: use multiple subscripts.');
- end
- idx = subs(2).subs{2};
- if isequal(idx,':'), idx = 1:numel(this.data); end
- for k=1:numel(idx)
- s = subs(2);
- s.subs{2} = 1;
- if numel(A) == 1
- this.data{idx(k)}.data = single(builtin('subsasgn',this.data{idx(k)}.data,s,A));
- else
- this.data{idx(k)}.data = single(builtin('subsasgn',this.data{idx(k)}.data,s,A(:,k)));
- end
- this.data{idx(k)}.attributes.Dim = size(this.data{idx(k)}.data);
- end
- end
+ this.data{n}.data = int32(A - 1);
+ this.data{n}.attributes.Dim = size(A);
+ end
+
+ %- .indices
+ %--------------------------------------------------------------
+ case 'indices'
+ if n ~= 1
+ this.data = this.data([n setdiff(1:numel(this.data),n)]);
+ n = 1;
+ end
+ if length(subs) > 1
+ this.data{n}.data = int32(builtin('subsasgn',this.data{n}.data,subs(2:end),A-1));
+ else
+ A = A(:);
+ this.data{n}.data = int32(A - 1);
+ this.data{n}.attributes.Dim = size(A);
+ end
+
+ %- .vertices, .normals, .cdata
+ %--------------------------------------------------------------
+ otherwise
+ if length(subs) > 1
+ if numel(n) == 1
+ this.data{n}.data = single(builtin('subsasgn',this.data{n}.data,subs(2:end),A));
+ this.data{n}.attributes.Dim = size(this.data{n}.data);
else
- if numel(n) == 1
- if isa(A,'file_array')
- this.data{n}.data = A;
- this.data{n}.attributes.Dim = A.dim;
+ if numel(subs(2).subs) == 1
+ error('Linear indexing not supported: use multiple subscripts.');
+ end
+ idx = subs(2).subs{2};
+ if isequal(idx,':'), idx = 1:numel(this.data); end
+ for k=1:numel(idx)
+ s = subs(2);
+ s.subs{2} = 1;
+ if numel(A) == 1
+ this.data{idx(k)}.data = single(builtin('subsasgn',this.data{idx(k)}.data,s,A));
else
- this.data{n}.data = single(A);
- this.data{n}.attributes.Dim = size(A);
+ this.data{idx(k)}.data = single(builtin('subsasgn',this.data{idx(k)}.data,s,A(:,k)));
end
+ this.data{idx(k)}.attributes.Dim = size(this.data{idx(k)}.data);
+ end
+ end
+ else
+ if numel(n) == 1
+ if isa(A,'file_array')
+ this.data{n}.data = A;
+ this.data{n}.attributes.Dim = A.dim;
else
- error('Syntax not implemented.');
+ this.data{n}.data = single(A);
+ this.data{n}.attributes.Dim = size(A);
end
+ else
+ error('Syntax not implemented.');
end
end
- end
end
+
case '()'
case '{}'
otherwise
diff --git a/@meeg/check.m b/@meeg/check.m
index 8684bfa6..96d72b66 100644
--- a/@meeg/check.m
+++ b/@meeg/check.m
@@ -13,7 +13,7 @@
% Copyright (C) 2008-2012 Wellcome Trust Centre for Neuroimaging
% Vladimir Litvak
-% $Id: check.m 5933 2014-03-28 13:22:28Z vladimir $
+% $Id: check.m 6542 2015-09-09 11:48:34Z karl $
if nargin == 1
option = 'basic';
@@ -147,7 +147,7 @@
if isequal(option, 'dcm')
if strcmp(option, 'dcm')
- if ~ismember(modality(this, 0), {'EEG', 'MEG', 'MEGPLANAR', 'Multimodal', 'LFP'})
+ if ~ismember(modality(this, 0), {'EEG', 'MEG', 'MEGPLANAR', 'Multimodal', 'LFP','ILAM'})
ok = 0;
disp('Unsupported modality for DCM');
end
diff --git a/@meeg/fiducials.m b/@meeg/fiducials.m
index f4466b42..322c971a 100644
--- a/@meeg/fiducials.m
+++ b/@meeg/fiducials.m
@@ -5,12 +5,12 @@
% Copyright (C) 2008-2012 Wellcome Trust Centre for Neuroimaging
% Vladimir Litvak
-% $Id: fiducials.m 5025 2012-10-31 14:44:13Z vladimir $
+% $Id: fiducials.m 6622 2015-12-03 11:54:13Z vladimir $
switch nargin
case 1
res = this.fiducials;
case 2
- this.fiducials = newfiducials;
+ this.fiducials = ft_struct2double(fixpnt(newfiducials));
res = this;
end
diff --git a/@meeg/meeg.m b/@meeg/meeg.m
index 868a7cc5..225ac873 100644
--- a/@meeg/meeg.m
+++ b/@meeg/meeg.m
@@ -46,6 +46,10 @@
% .bad - 0 or 1 flag to allow rejection of trials.
% .repl - for epochs that are averages - number of replications used
% for the average.
+% .tag - the user can put any data here that will be attached to
+% the respective trial. This is useful e.g. to make sure the
+% relation between regressors and data is not broken when
+% removing bad trials or merging files.
% .events - this is a structure array describing events related to
% each trial.
%
@@ -114,7 +118,7 @@
% Copyright (C) 2005-2011 Wellcome Trust Centre for Neuroimaging
% Vladimir Litvak
-% $Id: meeg.m 5343 2013-03-21 16:07:50Z vladimir $
+% $Id: meeg.m 6525 2015-08-20 10:03:16Z vladimir $
switch nargin
case 0
diff --git a/@meeg/modality.m b/@meeg/modality.m
index 989c2851..99e3fd29 100644
--- a/@meeg/modality.m
+++ b/@meeg/modality.m
@@ -12,7 +12,7 @@
% Copyright (C) 2008-2012 Wellcome Trust Centre for Neuroimaging
% Vladimir Litvak
-% $Id: modality.m 5212 2013-01-26 13:16:36Z vladimir $
+% $Id: modality.m 6542 2015-09-09 11:48:34Z karl $
if nargin == 1
scalp = 1;
@@ -47,6 +47,10 @@
list = [list {'LFP'}];
end
+if ~isempty(indchantype(this, 'ILAM')) && ~scalp
+ list = [list {'ILAM'}];
+end
+
switch numel(list)
case 0
res = 'Other';
diff --git a/@meeg/private/checkmeeg.m b/@meeg/private/checkmeeg.m
index 05ba14f5..2f0540b1 100644
--- a/@meeg/private/checkmeeg.m
+++ b/@meeg/private/checkmeeg.m
@@ -6,7 +6,7 @@
% Copyright (C) 2008-2014 Wellcome Trust Centre for Neuroimaging
% Vladimir Litvak
-% $Id: checkmeeg.m 6302 2015-01-13 16:11:27Z vladimir $
+% $Id: checkmeeg.m 6622 2015-12-03 11:54:13Z vladimir $
%-Initialise data dimensions
@@ -219,6 +219,11 @@
if ~isfield(this.trials, 'bad')
[this.trials.bad] = deal(0);
end
+
+ if ~isfield(this.trials, 'tag')
+ [this.trials.tag] = deal([]);
+ end
+
if ~isfield(this.trials, 'events')
[this.trials.events] = deal([]);
end
@@ -378,7 +383,7 @@
if ~isfield(this, 'fiducials')
this.fiducials = struct([]);
else
- this.fiducials = ft_struct2double(this.fiducials);
+ this.fiducials = ft_struct2double(fixpnt(this.fiducials));
end
if ~isfield(this, 'artifacts')
diff --git a/@meeg/private/fixpnt.m b/@meeg/private/fixpnt.m
new file mode 100644
index 00000000..d91eabaa
--- /dev/null
+++ b/@meeg/private/fixpnt.m
@@ -0,0 +1,42 @@
+function data = fixpnt(data, recurse)
+
+% helper function to replace pos by pnt
+
+% $Id: fixpnt.m 6682 2016-01-15 15:52:00Z vladimir $
+
+if nargin==1
+ recurse = 1;
+end
+
+if ~isa(data, 'struct')
+ return;
+end
+
+if numel(data)>1
+ % loop over all individual elements
+ clear tmp
+ for i=1:numel(data)
+ % this is to prevent an "Subscripted assignment between dissimilar structures" error
+ tmp(i) = fixpnt(data(i));
+ end
+ data = tmp;
+ clear tmp
+ return
+end
+
+% replace pos by pnt
+if isfield(data, 'pos')
+ data.pnt = data.pos;
+ data = rmfield(data, 'pos');
+end
+
+if recurse<3
+ % recurse into substructures, not too deep
+ fn = fieldnames(data);
+ fn = setdiff(fn, {'cfg'}); % don't recurse into the cfg structure
+ for i=1:length(fn)
+ if isstruct(data.(fn{i}))
+ data.(fn{i}) = fixpnt(data.(fn{i}), recurse+1);
+ end
+ end
+end
diff --git a/@meeg/private/getset.m b/@meeg/private/getset.m
index 2da4d308..ef49040f 100644
--- a/@meeg/private/getset.m
+++ b/@meeg/private/getset.m
@@ -5,7 +5,7 @@
% Copyright (C) 2008-2012 Wellcome Trust Centre for Neuroimaging
% Vladimir Litvak
-% $Id: getset.m 5935 2014-03-28 15:59:57Z vladimir $
+% $Id: getset.m 6535 2015-08-25 11:45:26Z vladimir $
this = struct(this);
@@ -25,7 +25,7 @@
res{i} = getfield(this, parent, {ind(i)}, fieldname);
end
- if isempty(res) || (all(cellfun('isclass', res, 'double') & ~cellfun('isempty', res)))
+ if isempty(res) || (all(cellfun('isclass', res, 'double') & (cellfun(@numel, res) == 1)))
res = [res{:}];
end
diff --git a/@meeg/selectchannels.m b/@meeg/selectchannels.m
index cb2e22af..ef6d81f8 100644
--- a/@meeg/selectchannels.m
+++ b/@meeg/selectchannels.m
@@ -10,7 +10,7 @@
% Copyright (C) 2010-2012 Wellcome Trust Centre for Neuroimaging
% Vladimir Litvak
-% $Id: selectchannels.m 5675 2013-10-09 14:27:17Z vladimir $
+% $Id: selectchannels.m 6535 2015-08-25 11:45:26Z vladimir $
if ischar(channels)
channels = {channels};
@@ -20,7 +20,8 @@
for i = 1:numel(channels)
if ismember(upper(channels{i}), ...
- {'ALL', 'EOG', 'ECG', 'EMG', 'EEG', 'MEG', 'MEGMAG', 'MEGGRAD', 'MEGPLANAR', 'MEGCOMB', 'REF', 'REFMAG', 'REFGRAD', 'LFP'})
+ {'ALL','MEG', 'MEGPLANAR', 'MEGMAG', 'MEGGRAD', 'MEGCOMB','EEG',...
+ 'EOG', 'ECG', 'EMG', 'LFP', 'SRC', 'PHYS', 'ILAM', 'OTHER', 'REF', 'REFMAG', 'REFGRAD'})
chanind = [chanind indchantype(this, upper(channels{i}))];
elseif strncmpi('regexp_', channels{i}, 7)
re = channels{i}(8:end);
diff --git a/@meeg/sensors.m b/@meeg/sensors.m
index 5fa960d3..0bc6c8b0 100644
--- a/@meeg/sensors.m
+++ b/@meeg/sensors.m
@@ -7,7 +7,7 @@
% Copyright (C) 2008-2012 Wellcome Trust Centre for Neuroimaging
% Vladimir Litvak
-% $Id: sensors.m 6374 2015-03-12 10:15:18Z vladimir $
+% $Id: sensors.m 6535 2015-08-25 11:45:26Z vladimir $
if nargin<2
error('Sensor type (EEG or MEG) must be specified');
@@ -36,11 +36,22 @@
this.sensors(1).meg = newsens;
res = check(this);
end
+ case 'src'
+ if nargin < 3
+ if isfield(this.sensors, 'src')
+ res = this.sensors.src;
+ else
+ res = [];
+ end
+ else
+ this.sensors(1).src = newsens;
+ res = check(this);
+ end
otherwise
error('Unsupported sensor type');
end
-if nargin < 3 && ~isempty(res) && this.montage.Mind > 0
+if nargin < 3 && ~isempty(res) && ismember(lower(type), {'eeg', 'meg'}) && this.montage.Mind > 0
sens = res;
montage = this.montage.M(this.montage.Mind);
if ~isempty(intersect(sens.label, montage.labelorg))
diff --git a/@meeg/subsref.m b/@meeg/subsref.m
index fbf933a7..fc1227dc 100644
--- a/@meeg/subsref.m
+++ b/@meeg/subsref.m
@@ -5,7 +5,7 @@
% Copyright (C) 2008-2013 Wellcome Trust Centre for Neuroimaging
% Vladimir Litvak, Stefan Kiebel
-% $Id: subsref.m 5710 2013-10-22 14:01:23Z guillaume $
+% $Id: subsref.m 6600 2015-11-12 13:07:41Z christophe $
if isempty(subs)
return;
@@ -32,7 +32,9 @@
end
if ischar(subs.subs{1})
% need to handle the case of a ':' argument
- if ~strcmp(subs.subs{1},':'), error('This shouldn''t happen....'); end
+ if ~strcmp(subs.subs{1},':'),
+ error('This shouldn''t happen....');
+ end
if length(subs.subs) == 1
chanidx = 1:dim(1);
subs.subs{2} = ':';
@@ -44,18 +46,21 @@
else
chanidx = subs.subs{1};
end
-
- %check if correct channel index
+
+ % check if correct channel index
if any(chanidx > nchannels(this))
error('channel index higher than number of channels in current montage')
end
% get corresponding rows of 'tra' matrix
traidx = this.montage.M(this.montage.Mind).tra(chanidx,:);
- %change subs to use only the necessary channels from data
+ % change subs to use only the necessary channels from data
lchan_o = find(any(traidx,1));
subs.subs{1} = lchan_o;
+
+ % need to handle the case of ':' arguments
if ischar(subs.subs{2})
if ~strcmp(subs.subs{2},':'), error('This shouldn''t happen....'); end
+ subs.subs{2} = 1:dim(2);
Ntb = dim(2);
else
Ntb = length(subs.subs{2});
@@ -85,9 +90,9 @@
if ii mm
+%
+% Inputs
+% XYZ - 3xN voxel coordinates of N blob values
+% vals - N blob intensity values
+% mat - 4x4 matrix specifying voxels -> mm
% imgno - slice overlay img number to add to (defaults last in object)
%
% Outputs
-% obj - modified object
-%
-% $Id: add_blobs.m,v 1.1 2005/04/20 15:05:36 matthewbrett Exp $
+% obj - modified object
+%__________________________________________________________________________
+
+% Matthew Brett
+% $Id: add_blobs.m 6623 2015-12-03 18:38:08Z guillaume $
if nargin < 4
- error('Need all of object, xyz, vals, mat');
+ error('Need all of object, xyz, vals, mat');
end
if nargin < 5
- imgno = [];
+ imgno = [];
end
if isempty(imgno)
- imgno = length(obj.img);
+ imgno = length(obj.img);
end
if ~isempty(xyz)
- obj.img(imgno).vol = pr_blobs2vol(xyz,vals,mat);
+ obj.img(imgno).vol = pr_blobs2vol(xyz,vals,mat);
end
-
diff --git a/@slover/add_matrix.m b/@slover/add_matrix.m
index e91661be..8a3a5c15 100644
--- a/@slover/add_matrix.m
+++ b/@slover/add_matrix.m
@@ -1,30 +1,32 @@
function obj = add_matrix(obj, mat3d, mat, imgno)
-% adds 3d matrix image vol to slice overlay
-% FORMAT obj = add_matrix(imgno, mat3d, mat)
+% Add 3d matrix image vol to slice overlay
+% FORMAT obj = add_matrix(obj, mat3d, mat, imgno)
%
% Inputs
% obj - object
% mat3d - 3D matrix to add as img
% mat - optional 4x4 voxel->world translation
% imgno - optional img no to add to (defaults to last in object)
-%
+%
% Ouputs
% obj - modified object
-%
-% $Id: add_matrix.m,v 1.1 2005/04/20 15:05:36 matthewbrett Exp $
+%__________________________________________________________________________
+
+% Matthew Brett
+% $Id: add_matrix.m 6623 2015-12-03 18:38:08Z guillaume $
if nargin < 2
- return
+ return
end
if nargin < 3
- mat = [];
+ mat = [];
end
if nargin < 4
- imgno = [];
+ imgno = [];
end
if isempty(imgno)
- imgno = length(obj.img);
+ imgno = length(obj.img);
end
if ~isempty(mat3d)
- obj.img(imgno).vol = pr_matrix2vol(mat3d, mat);
+ obj.img(imgno).vol = pr_matrix2vol(mat3d, mat);
end
diff --git a/@slover/add_spm.m b/@slover/add_spm.m
index a95edfa8..eaaee601 100644
--- a/@slover/add_spm.m
+++ b/@slover/add_spm.m
@@ -1,11 +1,13 @@
function obj = add_spm(obj,xSPM)
-% Adds SPM blobs as new img to object, split effect, 'hot' colormap
+% Add SPM blobs as new img to object, split effect, 'hot' colormap
% FORMAT obj = add_spm(obj)
-%
+%
% SPM results are fetched from the workspace
-%
-% $Id: add_spm.m,v 1.1 2005/04/20 15:05:36 matthewbrett Exp $
-
+%__________________________________________________________________________
+
+% Matthew Brett
+% $Id: add_spm.m 6623 2015-12-03 18:38:08Z guillaume $
+
if nargin == 2
XYZ = xSPM.XYZ;
Z = xSPM.Z;
@@ -14,8 +16,8 @@
[XYZ,Z,M] = pr_get_spm_results;
end
if isempty(XYZ)
- warning('slover:noSPM', 'No SPM results to add');
- return
+ warning('slover:noSPM', 'No SPM results to add');
+ return
end
newimg = length(obj.img)+1;
diff --git a/@slover/display.m b/@slover/display.m
index 30b0a2a7..661832b9 100644
--- a/@slover/display.m
+++ b/@slover/display.m
@@ -1,19 +1,21 @@
function display(obj)
-% display method for slice overlay object
-%
-% $Id: display.m,v 1.1 2005/04/20 15:05:36 matthewbrett Exp $
-
+% Display method for slice overlay object
+%__________________________________________________________________________
+
+% Matthew Brett
+% $Id: display.m 6623 2015-12-03 18:38:08Z guillaume $
+
X = struct(obj);
src = '[slice overlay object]';
if isequal(get(0,'FormatSpacing'),'compact')
- disp([inputname(1) ' =']);
- disp(src);
- disp(X)
+ disp([inputname(1) ' =']);
+ disp(src);
+ disp(X)
else
- disp(' ')
- disp([inputname(1) ' =']);
- disp(' ');
- disp(src);
- disp(' ');
- disp(X)
-end
\ No newline at end of file
+ disp(' ')
+ disp([inputname(1) ' =']);
+ disp(' ');
+ disp(src);
+ disp(' ');
+ disp(X)
+end
\ No newline at end of file
diff --git a/@slover/fill_defaults.m b/@slover/fill_defaults.m
index c3e8ac0e..4d8347d9 100644
--- a/@slover/fill_defaults.m
+++ b/@slover/fill_defaults.m
@@ -1,109 +1,111 @@
function obj = fill_defaults(obj)
-% check and fill fields in object
+% Check and fill fields in object
% FORMAT obj = fill_defaults(obj)
-%
+%
% Input
% obj - object to fill
-%
+%
% Output
% obj - object filled
-%
-% $Id: fill_defaults.m,v 1.2 2005/05/06 22:59:56 matthewbrett Exp $
+%__________________________________________________________________________
+
+% Matthew Brett
+% $Id: fill_defaults.m 6623 2015-12-03 18:38:08Z guillaume $
% Some default structures
def_labs = struct('colour',[1 1 1],'size',0.075,'format', '%+3.0f');
def_fig = struct('position', [0 0 1 0.92], 'units', 'normalized', ...
- 'valign', 'top');
+ 'valign', 'top');
def_area = struct('position', [0 0 1 1], ...
- 'units', '', ...
- 'halign', 'center',...
- 'valign', 'middle');
+ 'units', '', ...
+ 'halign', 'center',...
+ 'valign', 'middle');
% Figure. We allow the figure to be dead, if we are going to resurrect
% it later.
dead_f = 0;
if ~isempty(obj.figure)
- % Is it dead?
- if ~ishandle(obj.figure)
- % Do we want to revive it?
- if ~obj.resurrectf
- error('Figure handle is not a valid figure')
- end
- dead_f = 1;
- obj.refreshf = 1;
- elseif ~strcmp(get(obj.figure,'Type'),'figure')
- error('Figure handle is not a figure')
- end
+ % Is it dead?
+ if ~ishandle(obj.figure)
+ % Do we want to revive it?
+ if ~obj.resurrectf
+ error('Figure handle is not a valid figure')
+ end
+ dead_f = 1;
+ obj.refreshf = 1;
+ elseif ~strcmp(get(obj.figure,'Type'),'figure')
+ error('Figure handle is not a figure')
+ end
else
- % no figure handle. Try spm figure, then gcf
- obj.figure = spm_figure('FindWin', 'Graphics');
- if isempty(obj.figure)
- obj.figure = gcf;
- end
+ % no figure handle. Try spm figure, then gcf
+ obj.figure = spm_figure('FindWin', 'Graphics');
+ if isempty(obj.figure)
+ obj.figure = gcf;
+ end
end
-% set defaults for SPM figure
+% set defaults for SPM figure
if ~dead_f
- if strcmp(get(obj.figure, 'Tag'),'Graphics')
- % position figure nicely for SPM
- obj.area = mars_struct('fillafromb', obj.area, def_fig);
- end
+ if strcmp(get(obj.figure, 'Tag'),'Graphics')
+ % position figure nicely for SPM
+ obj.area = mars_struct('fillafromb', obj.area, def_fig);
+ end
end
% orientation; string or 4x4 matrix
if ischar(obj.transform)
- orientn = find(strcmpi(obj.transform, {'axial', ...
- 'coronal', ...
- 'sagittal'}));
- if isempty(orientn)
- error('Unexpected orientation %s', obj.transform);
- end
- ts = [0 0 0 0 0 0 1 1 1;...
- 0 0 0 pi/2 0 0 1 -1 1;...
- 0 0 0 pi/2 0 -pi/2 -1 1 1];
- obj.transform = spm_matrix(ts(orientn,:));
+ orientn = find(strcmpi(obj.transform, {'axial', ...
+ 'coronal', ...
+ 'sagittal'}));
+ if isempty(orientn)
+ error('Unexpected orientation %s', obj.transform);
+ end
+ ts = [0 0 0 0 0 0 1 1 1;...
+ 0 0 0 pi/2 0 0 1 -1 1;...
+ 0 0 0 pi/2 0 -pi/2 -1 1 1];
+ obj.transform = spm_matrix(ts(orientn,:));
end
% default slice size, slice matrix depends on orientation
if (isempty(obj.slicedef) || isempty(obj.slices)) ...
- && ~isempty(obj.img)
- % take image sizes from first image
- V = obj.img(1).vol;
- D = V.dim(1:3);
- T = obj.transform * V.mat;
- vcorners = [1 1 1; D(1) 1 1; 1 D(2) 1; D(1:2) 1; ...
- 1 1 D(3); D(1) 1 D(3); 1 D(2:3) ; D(1:3)]';
- corners = T * [vcorners; ones(1,8)];
- SC = sort(corners, 2);
- vxsz = sqrt(sum(T(1:3,1:3).^2));
-
- if isempty(obj.slicedef)
- obj.slicedef = [SC(1,1) vxsz(1) SC(1,8);SC(2,1) vxsz(2) SC(2,8)];
- end
- if isempty(obj.slices)
- obj.slices = SC(3,1):vxsz(3):SC(3,8);
- end
+ && ~isempty(obj.img)
+ % take image sizes from first image
+ V = obj.img(1).vol;
+ D = V.dim(1:3);
+ T = obj.transform * V.mat;
+ vcorners = [1 1 1; D(1) 1 1; 1 D(2) 1; D(1:2) 1; ...
+ 1 1 D(3); D(1) 1 D(3); 1 D(2:3) ; D(1:3)]';
+ corners = T * [vcorners; ones(1,8)];
+ SC = sort(corners, 2);
+ vxsz = sqrt(sum(T(1:3,1:3).^2));
+
+ if isempty(obj.slicedef)
+ obj.slicedef = [SC(1,1) vxsz(1) SC(1,8);SC(2,1) vxsz(2) SC(2,8)];
+ end
+ if isempty(obj.slices)
+ obj.slices = SC(3,1):vxsz(3):SC(3,8);
+ end
end
% labels
if ischar(obj.labels)
- if ~strcmpi(obj.labels, 'none')
- error('If labels is string, should be ''none''');
- end
+ if ~strcmpi(obj.labels, 'none')
+ error('If labels is string, should be ''none''');
+ end
else
- obj.labels = mars_struct('fillafromb', obj.labels, def_labs);
- dist = mean(diff(obj.slices));
- prec = ceil(-min(log10(dist), 0));
- obj.labels.format = sprintf('%%+3.%1df', prec);
+ obj.labels = mars_struct('fillafromb', obj.labels, def_labs);
+ dist = mean(diff(obj.slices));
+ prec = ceil(-min(log10(dist), 0));
+ obj.labels.format = sprintf('%%+3.%1df', prec);
end
% figure area stuff
obj.area = mars_struct('fillafromb', obj.area, def_area);
if isempty(obj.area.units)
- if (all(obj.area.position>=0 & obj.area.position<=1))
- obj.area.units = 'normalized';
- else
- obj.area.units = 'pixels';
- end
+ if (all(obj.area.position>=0 & obj.area.position<=1))
+ obj.area.units = 'normalized';
+ else
+ obj.area.units = 'pixels';
+ end
end
% fill various img arguments
@@ -111,76 +113,75 @@
% set colour intensities as we go
remcol = 1;
for i = 1:length(obj.img)
- if ~mars_struct('isthere', obj.img(i), 'type')
- % default is true colour, unless prop is Inf
- obj.img(i).type = 'truecolour';
- if mars_struct('isthere', obj.img(i), 'prop')
- if obj.img(i).prop == Inf
- obj.img(i).type = 'split';
- obj.img(i).prop = 1;
- end
- end
- end
- if ~mars_struct('isthere', obj.img(i), 'hold')
- if ~mars_struct('isthere', obj.img(i).vol, 'imgdata')
- % normal file vol struct
- obj.img(i).hold = 1;
- else
- % 3d matrix vol struct
- obj.img(i).hold = 0;
- end
- end
- if ~mars_struct('isthere', obj.img(i), 'background')
- obj.img(i).background = NaN;
- end
- if ~mars_struct('isthere', obj.img(i), 'prop')
- % default is true colour
- if strcmpi(obj.img(i).type, 'truecolour')
- obj.img(i).prop = remcol/(length(obj.img)-i+1);
- remcol = remcol - obj.img(i).prop;
- else
- obj.img(i).prop = 1;
- end
- end
- if ~mars_struct('isthere', obj.img(i), 'range')
- [mx mn] = pr_volmaxmin(obj.img(i).vol);
- obj.img(i).range = [mn mx];
- end
- if ~mars_struct('isthere', obj.img(i), 'cmap')
- if strcmpi(obj.img(i).type, 'split')
- if obj.range(1)= minnpanels);
- if isempty(tmp)
- error('Whoops, cannot fit panels onto figure');
+
+ % calculate area of display in pixels
+ parea = obj.area.position;
+ if ~strcmp(obj.area.units, 'pixels')
+ ubu = get(obj.figure, 'units');
+ set(obj.figure, 'units','pixels');
+ tmp = get(obj.figure, 'Position');
+ ascf = tmp(3:4);
+ if ~strcmp(obj.area.units, 'normalized')
+ set(obj.figure, 'units',obj.area.units);
+ tmp = get(obj.figure, 'Position');
+ ascf = ascf ./ tmp(3:4);
+ end
+ set(figno, 'Units', ubu);
+ parea = parea .* repmat(ascf, 1, 2);
end
- b = tmp(1); % best fitting scaling
- panels = panels(:,b);
- axlen = axlen(:, b);
- else
- % if xslices is specified, assume X is flush with X figure dimensions
- panels(X:Y,1) = [obj.xslices; 0];
- axlen(X:Y,1) = [asz(X)/panels(X); 0];
- end
-
- % Axis dimensions are in pixels. This prevents aspect ratio rescaling
- panels(Y) = ceil(minnpanels/panels(X));
- axlen(Y) = axlen(X)*yxratio;
-
- % centre (etc) panels in display area as required
- divs = [Inf 2 1];the_ds = [0;0];
- the_ds(X) = divs(strcmp(obj.area.halign, {'left','center','right'}));
- the_ds(Y) = divs(strcmp(obj.area.valign, {'bottom','middle','top'}));
- startc = parea(1:2)' + (asz'-(axlen.*panels))./the_ds;
-
- % make axes for panels
- r=0;c=1;
- npanels = prod(panels);
- lastempty = npanels-cbars;
- axisd = nan(1, npanels);
- for i = 1:npanels
- % panel userdata
- if i<=nslices
- u.type = 'slice';
- u.no = zmm(i);
- elseif i > lastempty
- u.type = 'cbar';
- u.no = i - lastempty;
+ asz = parea(3:4);
+
+ % by default, make most parsimonious fit to figure
+ yxratio = length(ymm)*dims(Y,2)/(length(xmm)*dims(X,2));
+ if isempty(obj.xslices)
+ % iteration needed to optimize, surprisingly. Thanks to Ian NS
+ axlen(X,:)=asz(1):-1:1;
+ axlen(Y,:)=yxratio*axlen(X,:);
+ panels = floor(asz'*ones(1,size(axlen,2))./axlen);
+ estnpanels = prod(panels);
+ tmp = find(estnpanels >= minnpanels);
+ if isempty(tmp)
+ error('Whoops, cannot fit panels onto figure');
+ end
+ b = tmp(1); % best fitting scaling
+ panels = panels(:,b);
+ axlen = axlen(:, b);
else
- u.type = 'empty';
- u.no = i - nslices;
+ % if xslices is specified, assume X is flush with X figure dimensions
+ panels(X:Y,1) = [obj.xslices; 0];
+ axlen(X:Y,1) = [asz(X)/panels(X); 0];
end
- axpos = [r*axlen(X)+startc(X) (panels(Y)-c)*axlen(Y)+startc(Y) axlen'];
- axisd(i) = axes(...
- 'Parent',figno,...
- 'XTick',[],...
- 'XTickLabel',[],...
- 'YTick',[],...
- 'YTickLabel',[],...
- 'Box','on',...
- 'XLim',[1 vdims(X)],...
- 'YLim',[1 vdims(Y)],...
- 'Units', 'pixels',...
- 'Position',axpos,...
- 'Tag','slice overlay panel',...
- 'UserData',u);
- r = r+1;
- if r >= panels(X)
- r = 0;
- c = c+1;
+
+ % Axis dimensions are in pixels. This prevents aspect ratio rescaling
+ panels(Y) = ceil(minnpanels/panels(X));
+ axlen(Y) = axlen(X)*yxratio;
+
+ % centre (etc) panels in display area as required
+ divs = [Inf 2 1];the_ds = [0;0];
+ the_ds(X) = divs(strcmp(obj.area.halign, {'left','center','right'}));
+ the_ds(Y) = divs(strcmp(obj.area.valign, {'bottom','middle','top'}));
+ startc = parea(1:2)' + (asz'-(axlen.*panels))./the_ds;
+
+ % make axes for panels
+ r=0;c=1;
+ npanels = prod(panels);
+ lastempty = npanels-cbars;
+ axisd = nan(1, npanels);
+ for i = 1:npanels
+ % panel userdata
+ if i<=nslices
+ u.type = 'slice';
+ u.no = zmm(i);
+ elseif i > lastempty
+ u.type = 'cbar';
+ u.no = i - lastempty;
+ else
+ u.type = 'empty';
+ u.no = i - nslices;
+ end
+ axpos = [r*axlen(X)+startc(X) (panels(Y)-c)*axlen(Y)+startc(Y) axlen'];
+ axisd(i) = axes(...
+ 'Parent',figno,...
+ 'XTick',[],...
+ 'XTickLabel',[],...
+ 'YTick',[],...
+ 'YTickLabel',[],...
+ 'Box','on',...
+ 'XLim',[1 vdims(X)],...
+ 'YLim',[1 vdims(Y)],...
+ 'Units', 'pixels',...
+ 'Position',axpos,...
+ 'Tag','slice overlay panel',...
+ 'UserData',u);
+ r = r+1;
+ if r >= panels(X)
+ r = 0;
+ c = c+1;
+ end
end
- end
end
% sort out labels
if ischar(obj.labels)
- do_labels = ~strcmpi(obj.labels, 'none');
+ do_labels = ~strcmpi(obj.labels, 'none');
else
- do_labels = 1;
+ do_labels = 1;
end
if do_labels
- labels = obj.labels;
- if iscell(labels.format)
- if length(labels.format)~=vdims(Z)
- error('Oh dear, expecting %d labels, but found %d', ...
- vdims(Z), length(labels.contents));
- end
- else
- % format string for mm from AC labelling
- fstr = labels.format;
- labels.format = cell(vdims(Z),1);
- acpt = obj.transform * [0 0 0 1]';
- for i = 1:vdims(Z)
- labels.format(i) = {sprintf(fstr,zmm(i)-acpt(Z))};
+ labels = obj.labels;
+ if iscell(labels.format)
+ if length(labels.format)~=vdims(Z)
+ error('Oh dear, expecting %d labels, but found %d', ...
+ vdims(Z), length(labels.contents));
+ end
+ else
+ % format string for mm from AC labelling
+ fstr = labels.format;
+ labels.format = cell(vdims(Z),1);
+ acpt = obj.transform * [0 0 0 1]';
+ for i = 1:vdims(Z)
+ labels.format(i) = {sprintf(fstr,zmm(i)-acpt(Z))};
+ end
end
- end
end
% split images into picture and contour
@@ -208,16 +210,16 @@
lrn = zeros(npimgs,3);
cmaps = cell(npimgs);
for i = 1:npimgs
- cmaps(i)={obj.img(pictimgs(i)).cmap};
- lrnv = [obj.img(pictimgs(i)).outofrange, obj.img(pictimgs(i)).nancol];
- for j = 1:length(lrnv)
- if numel(lrnv{j})==1
- lrn(i,j) = lrnv{j};
- else
- cmaps(i) = {[cmaps{i}; lrnv{j}(1:3)]};
- lrn(i,j) = size(cmaps{i},1);
+ cmaps(i)={obj.img(pictimgs(i)).cmap};
+ lrnv = [obj.img(pictimgs(i)).outofrange, obj.img(pictimgs(i)).nancol];
+ for j = 1:length(lrnv)
+ if numel(lrnv{j})==1
+ lrn(i,j) = lrnv{j};
+ else
+ cmaps(i) = {[cmaps{i}; lrnv{j}(1:3)]};
+ lrn(i,j) = size(cmaps{i},1);
+ end
end
- end
end
% cycle through slices displaying images
@@ -226,149 +228,145 @@
zimg = zeros(pandims);
for i = 1:nslices
- ixyzmm = [x(:)';y(:)';ones(1,nvox)*zmm(i);ones(1,nvox)];
- img = zimg;
- for j = 1:npimgs
- thisimg = obj.img(pictimgs(j));
- i1 = sf_slice2panel(thisimg, ixyzmm, obj.transform, vdims);
- % rescale to colormap
- [csdata badvals]= pr_scaletocmap(...
- i1,...
- thisimg.range(1),...
- thisimg.range(2),...
- thisimg.cmap,...
- lrn(j,:));
- % take indices from colormap to make true colour image
- iimg = reshape(cmaps{j}(csdata(:),:),pandims);
- tmp = repmat(logical(~badvals),[1 1 3]);
- if strcmpi(thisimg.type, 'truecolour')
- img(tmp) = img(tmp) + iimg(tmp)*thisimg.prop;
- else % split colormap effect
- img(tmp) = iimg(tmp)*thisimg.prop;
- end
- end
- % threshold out of range values
- img(img>1) = 1;
-
- image('Parent', axisd(i),...
- 'ButtonDownFcn', obj.callback,...
- 'CData',img);
-
-
- % do contour plot
- for j=1:length(contimgs)
- thisimg = obj.img(contimgs(j));
- i1 = sf_slice2panel(thisimg, ixyzmm, obj.transform, vdims);
- if any(any(isfinite(i1)))
- i1(i1max(thisimg.range))=max(thisimg.range);
- if ~any(diff(i1(isfinite(i1)))), continue, end % skip empty planes
- if mars_struct('isthere', thisimg, 'linespec')
- linespec = thisimg.linespec;
- else
- linespec = 'w-';
- end
- set(axisd(i),'NextPlot','add');
- if mars_struct('isthere', thisimg, 'contours')
- [c,h] = contour(axisd(i), i1, thisimg.contours, linespec);
- else
- [c,h] = contour(axisd(i), i1, linespec);
- end
- if ~isempty(h)
- if ~mars_struct('isthere', thisimg, 'linespec')
- % need to reset colours; contour assumes you just set the figure's
- % colormap, but to overlay coloured contours on a greyscale image,
- % one needs to have everything in truecolour, setting individual
- % contour lines to their appropriate colour.
- % (updated for MATLAB 7 and above)
- convals = get(h, 'LevelList');
- if ~isempty(convals)
- csdata = pr_scaletocmap(...
- convals,...
- thisimg.range(1),...
- thisimg.range(2),...
- thisimg.cmap,...
- [1 size(thisimg.cmap,1) 1]);
- colvals = thisimg.cmap(csdata(:),:)*thisimg.prop;
- for ch = get(h, 'Children')' % (NB: transpose needed to loop)
- CData = get(ch, 'CData'); % (CData is constant with final NaN)
- colval = colvals(find(convals == CData(1), 1), :);
- set(ch, 'EdgeColor', colval)
+ ixyzmm = [x(:)';y(:)';ones(1,nvox)*zmm(i);ones(1,nvox)];
+ img = zimg;
+ for j = 1:npimgs
+ thisimg = obj.img(pictimgs(j));
+ i1 = sf_slice2panel(thisimg, ixyzmm, obj.transform, vdims);
+ % rescale to colormap
+ [csdata,badvals]= pr_scaletocmap(...
+ i1,...
+ thisimg.range(1),...
+ thisimg.range(2),...
+ thisimg.cmap,...
+ lrn(j,:));
+ % take indices from colormap to make true colour image
+ iimg = reshape(cmaps{j}(csdata(:),:),pandims);
+ tmp = repmat(logical(~badvals),[1 1 3]);
+ if strcmpi(thisimg.type, 'truecolour')
+ img(tmp) = img(tmp) + iimg(tmp)*thisimg.prop;
+ else % split colormap effect
+ img(tmp) = iimg(tmp)*thisimg.prop;
end
- end
end
- if mars_struct('isthere', thisimg, 'linewidth')
- set(h, 'LineWidth', thisimg.linewidth);
+ % threshold out of range values
+ img(img>1) = 1;
+
+ image('Parent', axisd(i),...
+ 'ButtonDownFcn', obj.callback,...
+ 'CData',img);
+
+
+ % do contour plot
+ for j=1:length(contimgs)
+ thisimg = obj.img(contimgs(j));
+ i1 = sf_slice2panel(thisimg, ixyzmm, obj.transform, vdims);
+ if any(any(isfinite(i1)))
+ i1(i1max(thisimg.range))=max(thisimg.range);
+ if ~any(diff(i1(isfinite(i1)))), continue, end % skip empty planes
+ if mars_struct('isthere', thisimg, 'linespec')
+ linespec = thisimg.linespec;
+ else
+ linespec = 'w-';
+ end
+ set(axisd(i),'NextPlot','add');
+ if mars_struct('isthere', thisimg, 'contours')
+ [c,h] = contour(axisd(i), i1, thisimg.contours, linespec);
+ else
+ [c,h] = contour(axisd(i), i1, linespec);
+ end
+ if ~isempty(h)
+ if ~mars_struct('isthere', thisimg, 'linespec')
+ % need to reset colours; contour assumes you just set the figure's
+ % colormap, but to overlay coloured contours on a greyscale image,
+ % one needs to have everything in truecolour, setting individual
+ % contour lines to their appropriate colour.
+ % (updated for MATLAB 7 and above)
+ convals = get(h, 'LevelList');
+ if ~isempty(convals)
+ csdata = pr_scaletocmap(...
+ convals,...
+ thisimg.range(1),...
+ thisimg.range(2),...
+ thisimg.cmap,...
+ [1 size(thisimg.cmap,1) 1]);
+ colvals = thisimg.cmap(csdata(:),:)*thisimg.prop;
+ for ch = get(h, 'Children')' % (NB: transpose needed to loop)
+ CData = get(ch, 'CData'); % (CData is constant with final NaN)
+ colval = colvals(find(convals == CData(1), 1), :);
+ set(ch, 'EdgeColor', colval)
+ end
+ end
+ end
+ if mars_struct('isthere', thisimg, 'linewidth')
+ set(h, 'LineWidth', thisimg.linewidth);
+ end
+ end
+ end
end
- end
+
+ if do_labels
+ text('Parent',axisd(i),...
+ 'Color', labels.colour,...
+ 'FontUnits', 'normalized',...
+ 'VerticalAlignment','bottom',...
+ 'HorizontalAlignment','left',...
+ 'Position', [1 1],...
+ 'FontSize',labels.size,...
+ 'ButtonDownFcn', obj.callback,...
+ 'String', labels.format{i});
end
- end
-
- if do_labels
- text('Parent',axisd(i),...
- 'Color', labels.colour,...
- 'FontUnits', 'normalized',...
- 'VerticalAlignment','bottom',...
- 'HorizontalAlignment','left',...
- 'Position', [1 1],...
- 'FontSize',labels.size,...
- 'ButtonDownFcn', obj.callback,...
- 'String', labels.format{i});
- end
end
for i = (nslices+1):npanels
- set(axisd(i),'Color',[0 0 0]);
+ set(axisd(i),'Color',[0 0 0]);
end
-% add colorbar(s)
+% add colorbar(s)
for i = 1:cbars
- axno = axisd(end-cbars+i);
- cbari = obj.img(obj.cbar(i));
- cml = size(cbari.cmap,1);
- p = get(axno, 'Position'); % position of last axis
- cw = p(3)*0.2;
- ch = p(4)*0.75;
- pc = p(3:4)/2;
- [axlims idxs] = sort(cbari.range);
- a=axes(...
- 'Parent',figno,...
- 'XTick',[],...
- 'XTickLabel',[],...
- 'Units', 'pixels',...
- 'YLim', axlims,...
- 'FontUnits', 'normalized',...
- 'FontSize', 0.075,...
- 'YColor',[1 1 1],...
- 'Tag', 'cbar',...
- 'Box', 'off',...
- 'Position',[p(1)+pc(1)-cw/2,p(2)+pc(2)-ch/2,cw,ch]...
- );
- image('Parent', a,...
- 'YData', axlims(idxs),...
- 'CData', reshape(cbari.cmap,[cml,1,3]));
+ axno = axisd(end-cbars+i);
+ cbari = obj.img(obj.cbar(i));
+ cml = size(cbari.cmap,1);
+ p = get(axno, 'Position'); % position of last axis
+ cw = p(3)*0.2;
+ ch = p(4)*0.75;
+ pc = p(3:4)/2;
+ [axlims,idxs] = sort(cbari.range);
+ a=axes(...
+ 'Parent',figno,...
+ 'XTick',[],...
+ 'XTickLabel',[],...
+ 'Units', 'pixels',...
+ 'YLim', axlims,...
+ 'FontUnits', 'normalized',...
+ 'FontSize', 0.075,...
+ 'YColor',[1 1 1],...
+ 'Tag', 'cbar',...
+ 'Box', 'off',...
+ 'Position',[p(1)+pc(1)-cw/2,p(2)+pc(2)-ch/2,cw,ch]...
+ );
+ image('Parent', a,...
+ 'YData', axlims(idxs),...
+ 'CData', reshape(cbari.cmap,[cml,1,3]));
end % colourbars
% Get stuff for figure, in case it dies later
obj.figure_struct = mars_struct('split', get(figno), fig_struct_fields);
-return
-
-% subfunctions
-% ------------
+%==========================================================================
function i1 = sf_slice2panel(img, xyzmm, transform, vdims)
% to voxel space of image
vixyz = (transform*img.vol.mat) \ xyzmm;
-% raw data
+% raw data
if mars_struct('isthere', img.vol, 'imgdata')
- V = img.vol.imgdata;
+ V = img.vol.imgdata;
else
- V = img.vol;
+ V = img.vol;
end
i1 = spm_sample_vol(V,vixyz(1,:),vixyz(2,:),vixyz(3,:), ...
- [img.hold img.background]);
+ [img.hold img.background]);
if mars_struct('isthere', img, 'func')
- eval(img.func);
+ eval(img.func);
end
% transpose to reverse X and Y for figure
i1 = reshape(i1, vdims(1:2))';
-return
diff --git a/@slover/point_vals.m b/@slover/point_vals.m
index aa7dcb6c..619966c0 100644
--- a/@slover/point_vals.m
+++ b/@slover/point_vals.m
@@ -1,24 +1,26 @@
function vals = point_vals(obj, XYZmm, holdlist)
-% returns values from all the images at points given in XYZmm
+% Return values from all the images at points given in XYZmm
% FORMAT vals = point_vals(obj, XYZmm, holdlist)
-%
+%
% (for the following, I is number of images in object, N is the number
% of points to resample from)
-% Input
+% Input
% obj - object
-% XYZmm - 3xN XYZ natrix of points (in mm)
-% holdlist - optional 1xI vector of resample hold values
+% XYZmm - 3xN XYZ natrix of points (in mm)
+% holdlist - optional 1xI vector of resample hold values
%
% Outputs
% vals - IxN vector of values in images
-%
-% $Id: point_vals.m,v 1.1 2005/04/20 15:05:36 matthewbrett Exp $
-
+%__________________________________________________________________________
+
+% Matthew Brett
+% $Id: point_vals.m 6623 2015-12-03 18:38:08Z guillaume $
+
if nargin < 2
- error('Need XYZmm');
+ error('Need XYZmm');
end
if nargin < 3
- holdlist = [obj.img(:).hold];
+ holdlist = [obj.img(:).hold];
end
X=1;Y=2;Z=3;
@@ -26,18 +28,16 @@
nvals = size(XYZmm,2);
vals = zeros(nimgs,nvals)+NaN;
if size(XYZmm,1)~=4
- XYZmm = [XYZmm(X:Z,:); ones(1,nvals)];
+ XYZmm = [XYZmm(X:Z,:); ones(1,nvals)];
end
for i = 1:nimgs
- I = obj.img(i);
- XYZ = I.vol.mat\XYZmm;
- if ~mars_struct('isthere', I.vol, 'imgdata')
- vol = I.vol;
- else
- vol = I.vol.imgdata;
- end
- vals(i,:) = spm_sample_vol(vol, XYZ(X,:), XYZ(Y,:),XYZ(Z,:),[holdlist(i) ...
- I.background]);
-end
-return
-
+ I = obj.img(i);
+ XYZ = I.vol.mat\XYZmm;
+ if ~mars_struct('isthere', I.vol, 'imgdata')
+ vol = I.vol;
+ else
+ vol = I.vol.imgdata;
+ end
+ vals(i,:) = spm_sample_vol(vol, XYZ(X,:), XYZ(Y,:),XYZ(Z,:),[holdlist(i) ...
+ I.background]);
+end
diff --git a/@slover/print_fig.m b/@slover/print_fig.m
index 858249e8..c1687c5f 100644
--- a/@slover/print_fig.m
+++ b/@slover/print_fig.m
@@ -1,28 +1,30 @@
function print_fig(obj, filename, printstr)
-% print slice overlay figure
+% Print slice overlay figure
% FORMAT print_fig(obj, filename, printstr)
-%
-% Input
+%
+% Input
% obj - object
% filename - optional filename to print to (obj.filename)
% printstr - optional string giving print command (obj.printstr)
%
% Based on spm_figure print, and including fix from thence for ps
% printing
-%
-% $Id: print_fig.m,v 1.1 2005/04/20 15:05:36 matthewbrett Exp $
-
+%__________________________________________________________________________
+
+% Matthew Brett
+% $Id: print_fig.m 6623 2015-12-03 18:38:08Z guillaume $
+
if nargin < 2
- filename = [];
+ filename = [];
end
if isempty(filename)
- filename = obj.printfile;
+ filename = obj.printfile;
end
if nargin < 3
- printstr = '';
+ printstr = '';
end
if isempty(printstr)
- printstr = obj.printstr;
+ printstr = obj.printstr;
end
%-Note current figure, & switch to figure to print
@@ -45,18 +47,16 @@ function print_fig(obj, filename, printstr)
tmp = [find(abs(errstr)==10),length(errstr)+1];
str = {errstr(1:tmp(1)-1)};
for i = 1:length(tmp)-1
- if tmp(i)+1 < tmp(i+1)
+ if tmp(i)+1 < tmp(i+1)
str = [str, {errstr(tmp(i)+1:tmp(i+1)-1)}];
end
end
str = [str, '','- print command is:',[' ',printstr ' ' filename],...
- '','- current directory is:',[' ',pwd],...
- '',' * nothing has been printed *'];
+ '','- current directory is:',[' ',pwd],...
+ '',' * nothing has been printed *'];
for i=1:length(str)
- disp(str{i});end
+ disp(str{i});end
end
set(H,{'Units'},un)
set(0,'CurrentFigure',cF)
-
-return
diff --git a/@slover/private/mars_struct.m b/@slover/private/mars_struct.m
index df8f416a..7055178e 100644
--- a/@slover/private/mars_struct.m
+++ b/@slover/private/mars_struct.m
@@ -1,13 +1,13 @@
function varargout = mars_struct(action, varargin)
-% multifunction function for manipulating structures
+% Multifunction function for manipulating structures
%
-% To help the exposition a bit:
-% 'fill' in a name, means that values empty or missing
+% To help the exposition a bit:
+% 'fill' in a name, means that values empty or missing
% in one structure are fetched from another
-%
+%
% 'merge' means simply that missing fields are added, with
% values, from a second structure (but not filled if empty)
-%
+%
% Each function needs to deal with the case of empty arguments
%
% FORMAT c = mars_struct('fillafromb', a, b, fieldns, flags)
@@ -20,7 +20,7 @@
% fields in b overwrite those in a)
% flags may also contain 'r', which Restricts fields to write from b, to
% those that are already present in a
-%
+%
% FORMAT [c, d] = mars_struct('split', a, b)
% split structure a into two, according to fields in b
% so that c becomes a structure which contains the fields
@@ -29,7 +29,7 @@
% or a cell array of fieldnames
%
% FORMAT [d] = mars_struct('strip', a, b)
-% strips all fields present in b from those in a,
+% strips all fields present in b from those in a,
% returning denuded structure as d. b can be a structure
% or a cell array of fieldnames. 'strip' is just 'split'
% but returning only the second argument
@@ -39,14 +39,14 @@
%
% FORMAT [c,d] = mars_struct('ffillsplit', a, b)
% force fill, followed by split
-% All fields from a, that are also present in b, and not empty in b,
-% are replaced with the values in b; the result is returned as c
+% All fields from a, that are also present in b, and not empty in b,
+% are replaced with the values in b; the result is returned as c
% Any fields present in a, but not present in b, are returned in d
%
% FORMAT c = mars_struct('ffillmerge', a, b)
% force fill followed by merge
% performs 'ffillsplit' on a and b, then merges a and b
-% All fields present in a or b are returned in c, but
+% All fields present in a or b are returned in c, but
% any fields present in both, now have the value from b
%
% FORMAT [c d] = mars_struct('splitmerge', a, b)
@@ -61,7 +61,7 @@
% The call is recursive if more than two arguments are passed
% Thus with structure s = struct('one', struct('two', 3))
% mars_struct('isthere', s, 'one', 'two') returns 1
-%
+%
% FORMAT z = mars_struct('getifthere', a, b [, c [, d ...])
% returns value of field named in b from a or [] if absent
% Call is recursive, like 'isthere' above.
@@ -69,193 +69,195 @@
% FORMAT strs = mars_struct('celldisp', a)
% returns output like disp(a) as a cell array
% Useful for printing text description of structure
-%
-% $Id: mars_struct.m,v 1.13 2004/09/22 16:02:38 matthewbrett Exp $
+%__________________________________________________________________________
+
+% Matthew Brett
+% $Id: mars_struct.m 6623 2015-12-03 18:38:08Z guillaume $
if nargin < 1
- error('Action needed');
+ error('Action needed');
end
if nargin < 2
- error('Must specify structure')
+ error('Must specify structure')
end
if nargin < 3
- varargin = {varargin{:} []};
+ varargin = {varargin{:} []};
end
-[a b] = deal(varargin{1:2});
+[a,b] = deal(varargin{1:2});
-switch lower(action)
- case 'fillafromb'
- % Return for empty passed args
- if isempty(a), varargout = {b}; return, end
- if isempty(b), varargout = {a}; return, end
- if nargin < 4, fieldns = []; else fieldns = varargin{3}; end
- if isempty(fieldns)
- if ~isstruct(b), error('Need struct as 2nd argument'); end
- fieldns = fieldnames(b);
- end
- if nargin < 5, flags = ''; else flags = varargin{4}; end
- if isempty(flags), flags = ' ';end
-
- if ischar(fieldns), fieldns=cellstr(fieldns);end
-
- af = fieldnames(a)';
- bf = fieldns';
-
- % classify fields 0 = a~b, 1 = a&b, 2=b~a
- cf = af;
- ftype = ismember(af, bf);
- if ~any(flags == 'r')
- b_not_a = find(~ismember(bf, af));
- cf = {cf{:} bf{b_not_a}};
- ftype = [ftype ones(1, length(b_not_a))*2];
- end
-
- % cope with arrays of structures
- alen = prod(size(a));
- blen = prod(size(b));
- maxlen = max(alen, blen);
-
- for si=1:maxlen
- ctmp = [];
- for i=1:length(cf)
- fn = cf{i};
- switch ftype(i)
- case 0 % a~b
- fval = getfield(a(si), fn);
- case 1 % shared field
- bfc = getfield(b(si), fn);
- if isempty(getfield(a(si), fn)) || ... % a field is empty
- (any(flags == 'f' & ~isempty(bfc)))% or force fill
- fval = bfc;
- else % field not empty, could be struct -> recurse
- fval = getfield(a(si),fn);
- if isstruct(fval) & isstruct(bfc)
- fval = mars_struct('fillafromb',fval,bfc);
- end
- end
- case 2 % b~a
- fval = getfield(b(si), fn);
- case 3 % no field information, see below
- fval = [];
- end
- if isempty(ctmp)
- ctmp = struct(fn, fval);
- else
- ctmp = setfield(ctmp, fn, fval);
- end
- end
- c(si) = ctmp;
-
- if si == blen % reached end of bs, rest of b~a fields are empty
- ftype = (ftype == 2) * 3;
- elseif si == alen % end of a's rest of a~b fields are empty
- ftype = (ftype == 0) * 2 + 1;
- end
-
- end
- varargout = {c};
-
- case 'split'
- if isempty(a), varargout = {a,a}; return, end
- if isempty(b), varargout = {b,a}; return, end
- d = a;
- c = [];
-
- if ischar(b), b = {b};end
- if isstruct(b), b = fieldnames(b);end
-
- for bf = b(:)'
- if isfield(a, bf{1})
- c = setfield(c, bf{1}, getfield(a, bf{1}));
- d = rmfield(d, bf{1});
- end
- end
- varargout = {c, d};
-
- case 'strip'
- [c d] = mars_struct('split', a, b);
- varargout = {d};
-
- case 'merge'
- if isempty(a), varargout = {b}; return, end
- if isempty(b), varargout = {a}; return, end
- c = a;
-
- for bf = fieldnames(b)';
- if ~isfield(a, bf{1})
- c = setfield(c, bf{1}, getfield(b, bf{1}));
- end
- end
- varargout = {c};
-
- case 'ffillsplit'
- if isempty(a) || isempty(b)
- % Nothing in common, return unchanged
- varargout = {a, b}; return
- end
- c = a; d = b;
-
- cf = fieldnames(c);
- for i=1:length(cf)
- if isfield(d, cf{i})
- dfc = getfield(d,cf{i});
- if ~isempty(dfc)
- c = setfield(c, cf{i}, dfc);
- end
- d = rmfield(d, cf{i});
- end
- end
- varargout = {c,d};
-
- case 'ffillmerge'
- [a b] = mars_struct('ffillsplit', a, b);
- varargout = {mars_struct('merge', a, b)};
-
- case 'splitmerge'
- [a c] = mars_struct('split', a, b);
- varargout = {mars_struct('merge', a, b) c};
-
- case 'isthere'
- if isempty(a), varargout = {0}; return, end
- c = mars_struct('getifthere', varargin{:});
- varargout = {~isempty(c)};
-
- case 'getifthere'
- if isempty(a), varargout = {[]}; return, end
- if isempty(b), varargout = {[]}; return, end
- for v = 2:nargin-1
- b = varargin{v};
- if ~isfield(a, b)
- varargout = {[]};
- return
- end
- a = getfield(a, b);
- end
- varargout = {a};
-
- case 'celldisp'
- if isempty(a), varargout = {{}}; return, end
- af = fieldnames(a);
- c = {};
- pad_len = size(char(af), 2) + 4;
- pad_str = ['%' num2str(pad_len) 's: %s'];
- for f = 1:length(af)
- d = getfield(a, af{f});
- cls = class(d);
- sz = size(d);
- szstr = sprintf('%dx', size(d));
- szstr(end) = [];
- switch cls
- case 'char'
- case {'double', 'float'}
- d = ['[' num2str(d) ']'];
- otherwise
- d = sprintf('[%s %s]', szstr, cls);
- end
- c{f} = sprintf(pad_str, af{f}, d);
- end
- varargout = {c};
-
- otherwise
- error(['Suspicious action was ' action]);
+switch lower(action)
+ case 'fillafromb'
+ % Return for empty passed args
+ if isempty(a), varargout = {b}; return, end
+ if isempty(b), varargout = {a}; return, end
+ if nargin < 4, fieldns = []; else fieldns = varargin{3}; end
+ if isempty(fieldns)
+ if ~isstruct(b), error('Need struct as 2nd argument'); end
+ fieldns = fieldnames(b);
+ end
+ if nargin < 5, flags = ''; else flags = varargin{4}; end
+ if isempty(flags), flags = ' ';end
+
+ if ischar(fieldns), fieldns=cellstr(fieldns);end
+
+ af = fieldnames(a)';
+ bf = fieldns';
+
+ % classify fields 0 = a~b, 1 = a&b, 2=b~a
+ cf = af;
+ ftype = ismember(af, bf);
+ if ~any(flags == 'r')
+ b_not_a = find(~ismember(bf, af));
+ cf = {cf{:} bf{b_not_a}};
+ ftype = [ftype ones(1, length(b_not_a))*2];
+ end
+
+ % cope with arrays of structures
+ alen = prod(size(a));
+ blen = prod(size(b));
+ maxlen = max(alen, blen);
+
+ for si=1:maxlen
+ ctmp = [];
+ for i=1:length(cf)
+ fn = cf{i};
+ switch ftype(i)
+ case 0 % a~b
+ fval = getfield(a(si), fn);
+ case 1 % shared field
+ bfc = getfield(b(si), fn);
+ if isempty(getfield(a(si), fn)) || ... % a field is empty
+ (any(flags == 'f' & ~isempty(bfc)))% or force fill
+ fval = bfc;
+ else % field not empty, could be struct -> recurse
+ fval = getfield(a(si),fn);
+ if isstruct(fval) && isstruct(bfc)
+ fval = mars_struct('fillafromb',fval,bfc);
+ end
+ end
+ case 2 % b~a
+ fval = getfield(b(si), fn);
+ case 3 % no field information, see below
+ fval = [];
+ end
+ if isempty(ctmp)
+ ctmp = struct(fn, fval);
+ else
+ ctmp = setfield(ctmp, fn, fval);
+ end
+ end
+ c(si) = ctmp;
+
+ if si == blen % reached end of bs, rest of b~a fields are empty
+ ftype = (ftype == 2) * 3;
+ elseif si == alen % end of a's rest of a~b fields are empty
+ ftype = (ftype == 0) * 2 + 1;
+ end
+
+ end
+ varargout = {c};
+
+ case 'split'
+ if isempty(a), varargout = {a,a}; return, end
+ if isempty(b), varargout = {b,a}; return, end
+ d = a;
+ c = [];
+
+ if ischar(b), b = {b};end
+ if isstruct(b), b = fieldnames(b);end
+
+ for bf = b(:)'
+ if isfield(a, bf{1})
+ c = setfield(c, bf{1}, getfield(a, bf{1}));
+ d = rmfield(d, bf{1});
+ end
+ end
+ varargout = {c, d};
+
+ case 'strip'
+ [c,d] = mars_struct('split', a, b);
+ varargout = {d};
+
+ case 'merge'
+ if isempty(a), varargout = {b}; return, end
+ if isempty(b), varargout = {a}; return, end
+ c = a;
+
+ for bf = fieldnames(b)';
+ if ~isfield(a, bf{1})
+ c = setfield(c, bf{1}, getfield(b, bf{1}));
+ end
+ end
+ varargout = {c};
+
+ case 'ffillsplit'
+ if isempty(a) || isempty(b)
+ % Nothing in common, return unchanged
+ varargout = {a, b}; return
+ end
+ c = a; d = b;
+
+ cf = fieldnames(c);
+ for i=1:length(cf)
+ if isfield(d, cf{i})
+ dfc = getfield(d,cf{i});
+ if ~isempty(dfc)
+ c = setfield(c, cf{i}, dfc);
+ end
+ d = rmfield(d, cf{i});
+ end
+ end
+ varargout = {c,d};
+
+ case 'ffillmerge'
+ [a,b] = mars_struct('ffillsplit', a, b);
+ varargout = {mars_struct('merge', a, b)};
+
+ case 'splitmerge'
+ [a,c] = mars_struct('split', a, b);
+ varargout = {mars_struct('merge', a, b) c};
+
+ case 'isthere'
+ if isempty(a), varargout = {0}; return, end
+ c = mars_struct('getifthere', varargin{:});
+ varargout = {~isempty(c)};
+
+ case 'getifthere'
+ if isempty(a), varargout = {[]}; return, end
+ if isempty(b), varargout = {[]}; return, end
+ for v = 2:nargin-1
+ b = varargin{v};
+ if ~isfield(a, b)
+ varargout = {[]};
+ return
+ end
+ a = getfield(a, b);
+ end
+ varargout = {a};
+
+ case 'celldisp'
+ if isempty(a), varargout = {{}}; return, end
+ af = fieldnames(a);
+ c = {};
+ pad_len = size(char(af), 2) + 4;
+ pad_str = ['%' num2str(pad_len) 's: %s'];
+ for f = 1:length(af)
+ d = getfield(a, af{f});
+ cls = class(d);
+ sz = size(d);
+ szstr = sprintf('%dx', size(d));
+ szstr(end) = [];
+ switch cls
+ case 'char'
+ case {'double', 'float'}
+ d = ['[' num2str(d) ']'];
+ otherwise
+ d = sprintf('[%s %s]', szstr, cls);
+ end
+ c{f} = sprintf(pad_str, af{f}, d);
+ end
+ varargout = {c};
+
+ otherwise
+ error(['Suspicious action was ' action]);
end % switch
diff --git a/@slover/private/pr_basic_ui.m b/@slover/private/pr_basic_ui.m
index 02ce17d4..5294e0a4 100644
--- a/@slover/private/pr_basic_ui.m
+++ b/@slover/private/pr_basic_ui.m
@@ -7,23 +7,25 @@
% imgs - string or cell array of image names to display
% (defaults to GUI select if no arguments passed)
% dispf - optional flag: if set, displays overlay (default = 1)
-%
-% $Id: pr_basic_ui.m,v 1.1 2005/04/20 15:05:00 matthewbrett Exp $
-
+%__________________________________________________________________________
+
+% Matthew Brett
+% $Id: pr_basic_ui.m 6623 2015-12-03 18:38:08Z guillaume $
+
if nargin < 1
- imgs = '';
+ imgs = '';
end
if isempty(imgs)
- [imgs, sts] = spm_select([1 Inf], 'image', 'Image(s) to display');
- if ~sts, obj=[]; return; end
+ [imgs, sts] = spm_select([1 Inf], 'image', 'Image(s) to display');
+ if ~sts, obj=[]; return; end
end
if ischar(imgs)
- imgs = cellstr(imgs);
+ imgs = cellstr(imgs);
end
if nargin < 2
- dispf = 1;
+ dispf = 1;
end
-
+
spm_input('!SetNextPos', 1);
% load images
@@ -41,78 +43,78 @@
deftype = 1;
obj.cbar = [];
for i = 1:nimgs
- obj.img(i).vol = spm_vol(imgs{i});
- options = {'Structural','Truecolour', ...
- 'Blobs','Negative blobs','Contours'};
- % if there are SPM results in the workspace, add this option
- [XYZ Z M] = pr_get_spm_results;
- if ~isempty(XYZ)
- options = {'Structural with SPM blobs', options{:}};
- end
- itype = spm_input(sprintf('Img %d: %s - image type?', i, imgns{i}), '+1', ...
- 'm', char(options),options, deftype);
- imgns(i) = {sprintf('Img %d (%s)',i,itype{1})};
- [mx mn] = slover('volmaxmin', obj.img(i).vol);
- if ~isempty(strmatch('Structural', itype))
- obj.img(i).type = 'truecolour';
- obj.img(i).cmap = gray;
- obj.img(i).range = [mn mx];
- deftype = 2;
- cscale = [cscale i];
- if strcmp(itype,'Structural with SPM blobs')
- obj = add_spm(obj);
+ obj.img(i).vol = spm_vol(imgs{i});
+ options = {'Structural','Truecolour', ...
+ 'Blobs','Negative blobs','Contours'};
+ % if there are SPM results in the workspace, add this option
+ [XYZ,Z,M] = pr_get_spm_results;
+ if ~isempty(XYZ)
+ options = {'Structural with SPM blobs', options{:}};
end
- else
- cprompt = ['Colormap: ' imgns{i}];
- switch itype{1}
- case 'Truecolour'
- obj.img(i).type = 'truecolour';
- dcmap = 'flow.lut';
- drange = [mn mx];
- cscale = [cscale i];
- obj.cbar = [obj.cbar i];
- case 'Blobs'
- obj.img(i).type = 'split';
- dcmap = 'hot';
- drange = [0 mx];
- obj.img(i).prop = 1;
- obj.cbar = [obj.cbar i];
- case 'Negative blobs'
- obj.img(i).type = 'split';
- dcmap = 'winter';
- drange = [0 mn];
- obj.img(i).prop = 1;
- obj.cbar = [obj.cbar i];
- case 'Contours'
- obj.img(i).type = 'contour';
- dcmap = 'white';
- drange = [mn mx];
- obj.img(i).prop = 1;
+ itype = spm_input(sprintf('Img %d: %s - image type?', i, imgns{i}), '+1', ...
+ 'm', char(options),options, deftype);
+ imgns(i) = {sprintf('Img %d (%s)',i,itype{1})};
+ [mx,mn] = slover('volmaxmin', obj.img(i).vol);
+ if ~isempty(strmatch('Structural', itype))
+ obj.img(i).type = 'truecolour';
+ obj.img(i).cmap = gray;
+ obj.img(i).range = [mn mx];
+ deftype = 2;
+ cscale = [cscale i];
+ if strcmp(itype,'Structural with SPM blobs')
+ obj = add_spm(obj);
+ end
+ else
+ cprompt = ['Colormap: ' imgns{i}];
+ switch itype{1}
+ case 'Truecolour'
+ obj.img(i).type = 'truecolour';
+ dcmap = 'flow.lut';
+ drange = [mn mx];
+ cscale = [cscale i];
+ obj.cbar = [obj.cbar i];
+ case 'Blobs'
+ obj.img(i).type = 'split';
+ dcmap = 'hot';
+ drange = [0 mx];
+ obj.img(i).prop = 1;
+ obj.cbar = [obj.cbar i];
+ case 'Negative blobs'
+ obj.img(i).type = 'split';
+ dcmap = 'winter';
+ drange = [0 mn];
+ obj.img(i).prop = 1;
+ obj.cbar = [obj.cbar i];
+ case 'Contours'
+ obj.img(i).type = 'contour';
+ dcmap = 'white';
+ drange = [mn mx];
+ obj.img(i).prop = 1;
+ end
+ obj.img(i).cmap = sf_return_cmap(cprompt, dcmap);
+ obj.img(i).range = spm_input('Img val range for colormap','+1', 'e', drange, 2);
end
- obj.img(i).cmap = sf_return_cmap(cprompt, dcmap);
- obj.img(i).range = spm_input('Img val range for colormap','+1', 'e', drange, 2);
- end
end
ncmaps=length(cscale);
if ncmaps == 1
- obj.img(cscale).prop = 1;
+ obj.img(cscale).prop = 1;
else
- remcol=1;
- for i = 1:ncmaps
- ino = cscale(i);
- obj.img(ino).prop = spm_input(sprintf('%s intensity',imgns{ino}),...
- '+1', 'e', ...
- remcol/(ncmaps-i+1),1);
- remcol = remcol - obj.img(ino).prop;
- end
+ remcol=1;
+ for i = 1:ncmaps
+ ino = cscale(i);
+ obj.img(ino).prop = spm_input(sprintf('%s intensity',imgns{ino}),...
+ '+1', 'e', ...
+ remcol/(ncmaps-i+1),1);
+ remcol = remcol - obj.img(ino).prop;
+ end
end
-
+
obj.transform = deblank(spm_input('Image orientation', '+1', ['Axial|' ...
- ' Coronal|Sagittal'], strvcat('axial','coronal','sagittal'), ...
- 1));
+ ' Coronal|Sagittal'], strvcat('axial','coronal','sagittal'), ...
+ 1));
% use SPM figure window
-obj.figure = spm_figure('GetWin', 'Graphics');
+obj.figure = spm_figure('GetWin', 'Graphics');
% slices for display
obj = fill_defaults(obj);
@@ -120,24 +122,20 @@
dist = mean(diff(slices));
prec = ceil(-min(log10(dist), 0));
obj.slices = spm_input('Slices to display (mm)', '+1', 'e', ...
- sprintf('%0.*f:%0.*f:%0.*f',...
- prec, slices(1),...
- prec, dist,...
- prec, slices(end))...
- );
+ sprintf('%0.*f:%0.*f:%0.*f',...
+ prec, slices(1),...
+ prec, dist,...
+ prec, slices(end))...
+ );
% and do the display
if dispf, obj = paint(obj); end
-return
-
-% Subfunctions
-% ------------
+%==========================================================================
function cmap = sf_return_cmap(prompt,defmapn)
cmap = [];
while isempty(cmap)
- [cmap w]= slover('getcmap', spm_input(prompt,'+1','s', defmapn));
- if isempty(cmap), disp(w);end
+ [cmap,w]= slover('getcmap', spm_input(prompt,'+1','s', defmapn));
+ if isempty(cmap), disp(w);end
end
-return
diff --git a/@slover/private/pr_blobs2vol.m b/@slover/private/pr_blobs2vol.m
index 9fc647db..6edd42c2 100644
--- a/@slover/private/pr_blobs2vol.m
+++ b/@slover/private/pr_blobs2vol.m
@@ -1,30 +1,26 @@
function vol = pr_blobs2vol(xyz,vals,mat)
-% takes XYZ matrix and values, returns SPM matrix vol struct
+% Take XYZ matrix and values and return SPM matrix vol struct
% FORMAT vol = pr_blobs2vol(xyz,vals,mat)
-%
-% Inputs
+%
+% Inputs
% xyz - 3xN X Y Z coordinate matrix (in voxels)
% vals - 1xN values, one per coordinate
% mat - 4x4 voxel->world space transformation
-%
+%
% Outputs
% vol - vol struct, with matrix data 'imgdata' field
-%
-% $Id: pr_blobs2vol.m,v 1.1 2005/04/20 15:05:00 matthewbrett Exp $
-
-if nargin < 3
- error('Need XYZ, vals and mat');
-end
+%__________________________________________________________________________
+
+% Matthew Brett
+% $Id: pr_blobs2vol.m 6623 2015-12-03 18:38:08Z guillaume $
vol = [];
if ~isempty(xyz),
- rcp = round(xyz);
- vol.dim = max(rcp,[],2)';
- off = rcp(1,:) + vol.dim(1)*(rcp(2,:)-1+vol.dim(2)*(rcp(3,:)-1));
- vol.imgdata = zeros(vol.dim)+NaN;
- vol.imgdata(off) = vals;
- vol.imgdata = reshape(vol.imgdata,vol.dim);
- vol.mat = mat;
+ rcp = round(xyz);
+ vol.dim = max(rcp,[],2)';
+ off = rcp(1,:) + vol.dim(1)*(rcp(2,:)-1+vol.dim(2)*(rcp(3,:)-1));
+ vol.imgdata = zeros(vol.dim)+NaN;
+ vol.imgdata(off) = vals;
+ vol.imgdata = reshape(vol.imgdata,vol.dim);
+ vol.mat = mat;
end
-return
-
diff --git a/@slover/private/pr_get_spm_results.m b/@slover/private/pr_get_spm_results.m
index 60ebf681..0c17b3f4 100644
--- a/@slover/private/pr_get_spm_results.m
+++ b/@slover/private/pr_get_spm_results.m
@@ -1,31 +1,22 @@
-function [XYZ, Z, M] = pr_get_spm_results;
-% fetches SPM results, returns as point list
-% FORMAT [XYZ, Z, M] = pr_get_spm_results;
-%
+function [XYZ, Z, M] = pr_get_spm_results
+% Fetch SPM results and return as point list
+% FORMAT [XYZ, Z, M] = pr_get_spm_results
+%
% Outputs
% XYZ - XYZ point list in voxels (empty if not found)
% Z - values at points in XYZ
-% M - 4x4 voxel -> world transformation matrix
-%
-% $Id: pr_get_spm_results.m,v 1.2 2005/05/06 22:57:40 matthewbrett Exp $
-
+% M - 4x4 voxel -> world transformation matrix
+%__________________________________________________________________________
+
+% Matthew Brett
+% $Id: pr_get_spm_results.m 6623 2015-12-03 18:38:08Z guillaume $
+
errstr = '''Cannot find SPM results in workspace''';
-[XYZ Z M] = deal([]);
+[XYZ,Z,M] = deal([]);
-V = spm('ver');
-switch V(4:end)
- case '99'
- have_res = evalin('base', 'exist(''SPM'', ''var'')');
- if ~have_res, return, end
- SPM = evalin('base', 'SPM', ['error(' errstr ')']);
- XYZ = SPM.XYZ;
- Z = SPM.Z;
- M = evalin('base', 'VOL.M', ['error(' errstr ')']);
- otherwise
- have_res = evalin('base', 'exist(''xSPM'', ''var'')');
- if ~have_res, return, end
- xSPM = evalin('base', 'xSPM', ['error(' errstr ')']);
- XYZ = xSPM.XYZ;
- Z = xSPM.Z;
- M = xSPM.M;
-end
+have_res = evalin('base', 'exist(''xSPM'', ''var'')');
+if ~have_res, return, end
+xSPM = evalin('base', 'xSPM', ['error(' errstr ')']);
+XYZ = xSPM.XYZ;
+Z = xSPM.Z;
+M = xSPM.M;
diff --git a/@slover/private/pr_getcmap.m b/@slover/private/pr_getcmap.m
index 33e45f8d..b727ddbe 100644
--- a/@slover/private/pr_getcmap.m
+++ b/@slover/private/pr_getcmap.m
@@ -1,7 +1,7 @@
function [cmap, warnstr] = pr_getcmap(acmapname)
-% get colormap of name acmapname
+% Get colormap of name acmapname
% FORMAT [cmap, warnstr] = pr_getcmap(acmapname)
-%
+%
% Inputs
% acmapname - string. Can be (in order of precedence)
% - matrix name in base workspace
@@ -14,97 +14,98 @@
% cmap - Nx3 colormap matrix
% or empty if fails
% warnstr - warning message if fails
-%
-% $Id: pr_getcmap.m,v 1.1 2005/04/20 15:05:00 matthewbrett Exp $
+%__________________________________________________________________________
+
+% Matthew Brett
+% $Id: pr_getcmap.m 6623 2015-12-03 18:38:08Z guillaume $
-cmap = []; warnstr = [];
+cmap = []; warnstr = [];
if nargin < 1
- acmapname = '';
+ acmapname = '';
end
if isempty(acmapname)
- warnstr = 'No colormap name passed';
- return
+ warnstr = 'No colormap name passed';
+ return
end
% try a matrix first
cmap = evalin('base',acmapname,'[]');
if ~isempty(cmap)
- if size(cmap, 2)~=3
- warnstr = ['Colormap matrix ' acmapname ' was not N by 3'];
- cmap = [];
- end
- return
+ if size(cmap, 2)~=3
+ warnstr = ['Colormap matrix ' acmapname ' was not N by 3'];
+ cmap = [];
+ end
+ return
end
% not a matrix, is it...
% a colour name?
tmp = strcmpi(acmapname, {'red','green','blue','cyan', 'magenta', ...
- 'yellow', 'black', 'white'});
+ 'yellow', 'black', 'white'});
coldefs = [1 0 0;
- 0 1 0;
- 0 0 1;
- 0 1 1;
- 1 0 1;
- 1 1 0;
- 0 0 0;
- 1 1 1];
+ 0 1 0;
+ 0 0 1;
+ 0 1 1;
+ 1 0 1;
+ 1 1 0;
+ 0 0 0;
+ 1 1 1];
if any(tmp)
- coldef = coldefs(tmp, :);
- if ~any(diff(coldef))
- cmap = coldef;
- else
- cmap = (0:63)' * coldef / 63;
- end
- return
+ coldef = coldefs(tmp, :);
+ if ~any(diff(coldef))
+ cmap = coldef;
+ else
+ cmap = (0:63)' * coldef / 63;
+ end
+ return
end
% is it a file?
oname = acmapname;
-[p f e] = fileparts(acmapname);
+[p,f,e] = fileparts(acmapname);
% if no extension, add .mat
-if isempty(e)
- e = '.mat';
- acmapname = fullfile(p, [f e]);
+if isempty(e)
+ e = '.mat';
+ acmapname = fullfile(p, [f e]);
end
ef = exist(acmapname, 'file');
% file doesn't exist? Try home directory of this mfile
if ~ef
- mfp = fileparts(which(mfilename));
- acmapname = fullfile(mfp, [f e]);
- ef = exist(acmapname, 'file');
-end
+ mfp = fileparts(which(mfilename));
+ acmapname = fullfile(mfp, [f e]);
+ ef = exist(acmapname, 'file');
+end
if ~ef
- warnstr = ['No matrix or file ''' oname ''''];
- return
+ warnstr = ['No matrix or file ''' oname ''''];
+ return
end
% found file, get cmap
switch lower(e)
- case '.mat'
- % try for matrix of same name
- s = load(acmapname);
- if isfield(s, f)
- cmap = getfield(s, f);
- else % get first matrix in mat file
- s = struct2cell(s);
- cmap = s{1};
- end
- if size(cmap, 2)~=3
- warnstr = ['Colormap from ' acmapname ' was not an N by 3 matrix'];
- cmap = [];
- end
- case '.lut'
- fid = fopen(acmapname, 'rb');
- if fid~=-1
- cmap = fread(fid, Inf);
- l = length(cmap);
- if ~rem(l,3)
- cmap = reshape(cmap, l/3, 3) / 255;
- else
- warnstr = ['LUT map ' acmapname ' was wrong size'];
- end
- fclose(fid);
- else
- warnstr = ['Cannot open LUT colormap file ' acmapname];
- end
- otherwise
- warnstr = ['Unrecognized file extension ' e ' for ' acmapname];
+ case '.mat'
+ % try for matrix of same name
+ s = load(acmapname);
+ if isfield(s, f)
+ cmap = getfield(s, f);
+ else % get first matrix in mat file
+ s = struct2cell(s);
+ cmap = s{1};
+ end
+ if size(cmap, 2)~=3
+ warnstr = ['Colormap from ' acmapname ' was not an N by 3 matrix'];
+ cmap = [];
+ end
+ case '.lut'
+ fid = fopen(acmapname, 'rb');
+ if fid~=-1
+ cmap = fread(fid, Inf);
+ l = length(cmap);
+ if ~rem(l,3)
+ cmap = reshape(cmap, l/3, 3) / 255;
+ else
+ warnstr = ['LUT map ' acmapname ' was wrong size'];
+ end
+ fclose(fid);
+ else
+ warnstr = ['Cannot open LUT colormap file ' acmapname];
+ end
+ otherwise
+ warnstr = ['Unrecognized file extension ' e ' for ' acmapname];
end
-return
diff --git a/@slover/private/pr_matrix2vol.m b/@slover/private/pr_matrix2vol.m
index 60b8c503..12a52542 100644
--- a/@slover/private/pr_matrix2vol.m
+++ b/@slover/private/pr_matrix2vol.m
@@ -1,28 +1,30 @@
function vol = pr_matrix2vol(mat3d, mat)
-% returns (pseudo) vol struct for 3d matrix
+% Return (pseudo) vol struct for 3d matrix
% FORMAT vol = pr_matrix2vol(mat3d,mat)
%
% Inputs
% mat3d - 3D matrix
% mat - optional 4x4 voxel -> world transformation
-%
+%
% Outputs
% vol - kind of SPM vol struct with matrix data added
-%
-% $Id: pr_matrix2vol.m,v 1.1 2005/04/20 15:05:00 matthewbrett Exp $
-
+%__________________________________________________________________________
+
+% Matthew Brett
+% $Id: pr_matrix2vol.m 6623 2015-12-03 18:38:08Z guillaume $
+
if nargin < 1
- error('Need matrix to add to vol');
+ error('Need matrix to add to vol');
end
if nargin < 2
- mat = [];
+ mat = [];
end
if isempty(mat)
- mat = spm_matrix([]);
+ mat = spm_matrix([]);
end
vol = [];
if ~isempty(mat3d)
- vol.imgdata = mat3d;
- vol.mat = mat;
- vol.dim = size(mat3d);
+ vol.imgdata = mat3d;
+ vol.mat = mat;
+ vol.dim = size(mat3d);
end
diff --git a/@slover/private/pr_scaletocmap.m b/@slover/private/pr_scaletocmap.m
index 89a96dba..f1978e63 100644
--- a/@slover/private/pr_scaletocmap.m
+++ b/@slover/private/pr_scaletocmap.m
@@ -1,7 +1,7 @@
function [img, badvals]=pr_scaletocmap(inpimg,mn,mx,cmap,lrn)
-% scales image data to colormap, returning colormap indices
+% Scale image data to colormap, returning colormap indices
% FORMAT [img, badvals]=pr_scaletocmap(inpimg,mn,mx,cmap,lrn)
-%
+%
% Inputs
% inpimg - matrix containing image to scale
% mn - image value that maps to first value of colormap
@@ -13,39 +13,40 @@
% - lrn(3) (N=NaN) - NaN values
% If lrn value is 0, then colormap values are set to 1, and
% indices to these values are returned in badvals (below)
-%
+%
% Output
% img - inpimg scaled between 1 and (size(cmap, 1))
% badvals - indices into inpimg containing values out of range, as
% specified by lrn vector above
-%
-% $Id: pr_scaletocmap.m,v 1.1 2005/04/20 15:05:00 matthewbrett Exp $
+%__________________________________________________________________________
+
+% Matthew Brett
+% $Id: pr_scaletocmap.m 6623 2015-12-03 18:38:08Z guillaume $
if nargin < 4
- error('Need inpimg, mn, mx, and cmap');
+ error('Need inpimg, mn, mx, and cmap');
end
cml = size(cmap,1);
if nargin < 5
- lrn = [1 cml 0];
+ lrn = [1 cml 0];
end
img = (inpimg-mn)/(mx-mn); % img normalized to mn=0,mx=1
if cml==1 % values between 0 and 1 -> 1
- img(img>=0 & img<=1)=1;
+ img(img>=0 & img<=1)=1;
else
- img = img*(cml-1)+1;
+ img = img*(cml-1)+1;
end
outvals = {img<1, img>cml, isnan(img)};
img= round(img);
badvals = zeros(size(img));
for i = 1:length(lrn)
- if lrn(i)
- img(outvals{i}) = lrn(i);
- else
- badvals = badvals | outvals{i};
- img(outvals{i}) = 1;
- end
+ if lrn(i)
+ img(outvals{i}) = lrn(i);
+ else
+ badvals = badvals | outvals{i};
+ img(outvals{i}) = 1;
+ end
end
-return
diff --git a/@slover/private/pr_volmaxmin.m b/@slover/private/pr_volmaxmin.m
index 537a57ea..db6eb734 100644
--- a/@slover/private/pr_volmaxmin.m
+++ b/@slover/private/pr_volmaxmin.m
@@ -1,39 +1,39 @@
function [mx,mn] = pr_volmaxmin(vol)
-% returns max and min value in image volume
+% Return max and min value in image volume
% FORMAT [mx,mn] = pr_volmaxmin(vol)
-%
+%
% Input
% vol - image name or vol struct
-%
+%
% Outputs
% mx - maximum
% mn - minimum
-%
-% $Id: pr_volmaxmin.m,v 1.1 2005/04/20 15:05:00 matthewbrett Exp $
+%__________________________________________________________________________
+
+% Matthew Brett
+% $Id: pr_volmaxmin.m 6623 2015-12-03 18:38:08Z guillaume $
if nargin < 1
- error('Need volume to process');
+ error('Need volume to process');
end
if ischar(vol)
- vol = spm_vol(vol);
+ vol = spm_vol(vol);
end
if ~isstruct(vol)
- error('vol did not result in vol struct');
+ error('vol did not result in vol struct');
end
if mars_struct('isthere', vol, 'imgdata')
- tmp = vol.imgdata(isfinite(vol.imgdata));
- mx = max(tmp);
- mn = min(tmp);
+ tmp = vol.imgdata(isfinite(vol.imgdata));
+ mx = max(tmp);
+ mn = min(tmp);
else
mx = -Inf;mn=Inf;
for i=1:vol.dim(3),
- tmp = spm_slice_vol(vol,spm_matrix([0 0 i]),vol.dim(1:2),[0 NaN]);
- tmp = tmp(find(isfinite(tmp(:))));
- if ~isempty(tmp)
- mx = max([mx; tmp]);
- mn = min([mn; tmp]);
- end
+ tmp = spm_slice_vol(vol,spm_matrix([0 0 i]),vol.dim(1:2),[0 NaN]);
+ tmp = tmp(find(isfinite(tmp(:))));
+ if ~isempty(tmp)
+ mx = max([mx; tmp]);
+ mn = min([mn; tmp]);
+ end
end
end
-return
-
diff --git a/@slover/slover.m b/@slover/slover.m
index ce5a1946..1b9a56c4 100644
--- a/@slover/slover.m
+++ b/@slover/slover.m
@@ -2,8 +2,8 @@
% class constructor for slice overlay (slover) object
% FORMAT [o, others] = slover(params, others, varargin)
%
-% Inputs
-% params - either:
+% Inputs
+% params - either:
% - action string implementing class methods (see below)
% - array of image names / vol structs to display
% - structure with some fields for object (see below)
@@ -18,7 +18,7 @@
% - img - array of structs with information for images to display
% - img structs contain fields
% type - one of {'truecolour' 'split', 'contour'};
-% truecolour - displays transparent (see prop) image
+% truecolour - displays transparent (see prop) image
% overlaid with any previous
% split - in defined area, replaces image present (SPM
% type activation display)
@@ -30,7 +30,7 @@
% cmap - colormap for this image
% nancol - color for NaN. If scalar, this is an index into
% the image cmap. If 1x3 vector, it's a colour
-% prop - proportion of intensity for this cmap/img
+% prop - proportion of intensity for this cmap/img
% func - function to apply to image before scaling to cmap
% (and therefore before min/max thresholding. E.g. a func of
% 'i1(i1==0)=NaN' would convert zeros to NaNs
@@ -43,14 +43,14 @@
% colormap values < 1, i.e for image values <
% range(1), if (range(1)
% range(1) where (range(1)>range(2)). If missing,
-% display min (for Left) and max (for Right) value from colormap.
+% display min (for Left) and max (for Right) value from colormap.
% Otherwise should be a 2 element cell array, where
% the first element is the colour value for image values
% left of 'range', and the second is for image values
% right of 'range'. Scalar values for
% colour index the colormap, 3x1 vectors are colour
% values. An empty array attracts default settings
-% appropriate to the mode - i.e. transparent colour (where
+% appropriate to the mode - i.e. transparent colour (where
% img(n).type is truecolour), or split colour. Empty cells
% default to 0. 0 specifies that voxels with this
% colour do not influence the image (split =
@@ -61,11 +61,11 @@
% NaN
% linespec - string, applies only to contour map,
% e.g. 'w-' for white continuous lines
-% contours - vector, applies to contour map only, defines
-% values in image for which to show contours
+% contours - vector, applies to contour map only, defines
+% values in image for which to show contours
% (see help contours)
% linewidth - scalar, width in points of contour lines
-%
+%
% - transform - either - 4x4 transformation to apply to image slice position,
% relative to mm given by slicedef, before display
% or - text string, one of axial, coronal, sagittal
@@ -98,15 +98,15 @@
% halign - one of left,{center},right
% valign - one of top,{middle},bottom
% - xslices - no of slices to display across figure (defaults to an optimum)
-% - cbar - if empty, missing, no colourbar. If an array of integers, then
+% - cbar - if empty, missing, no colourbar. If an array of integers, then
% indexes img array, and makes colourbar for each cmap for
% that img. Cbars specified in order of appearance L->R
% - labels - struct can be:
% - empty (-> default numerical labels)
-% - 'none' (string) (no labels)
+% - 'none' (string) (no labels)
% - or contain fields:
-% colour - colour for label text
-% size - font size in units normalized to slice axes
+% colour - colour for label text
+% size - font size in units normalized to slice axes
% format - if = cell array of strings =
% labels for each slice in Z. If is string, specifies
% sprintf format string for labelling in distance of the
@@ -119,9 +119,9 @@
% mm of the position of a mouse click on one of the image
% slices, set callback to:
% 'get_pos(get(gcf, ''UserData''))'
-% To print the intensity values of the images at the clicked point:
+% To print the intensity values of the images at the clicked point:
% ['so_obj = get(gcf, ''UserData''); ' ...
-% 'point_vals(so_obj, get_pos(so_obj))']
+% 'point_vals(so_obj, get_pos(so_obj))']
% - printstr - string for printing slice overlay figure window, e.g.
% 'print -dpsc -painters -noui' (the default)
% - printfile - name of file to print output to; default 'slices.ps'
@@ -138,100 +138,102 @@
% in matrices as above
%
% FORMAT vol = slover('matrix2vol', mat3d, mat)
-% returns (pseudo) vol struct for 3d matrix
+% returns (pseudo) vol struct for 3d matrix
% input matrices as above
%
% FORMAT obj = slover('basic_ui' [,dispf])
% Runs basic UI to fetch some parameters, does display, returns object
% If optional dispf parameter = 0, supresses display
-%
-% $Id: slover.m,v 1.2 2005/05/06 22:59:56 matthewbrett Exp $
-
+%__________________________________________________________________________
+
+% Matthew Brett
+% $Id: slover.m 6623 2015-12-03 18:38:08Z guillaume $
+
myclass = 'slover';
% Default object structure
defstruct = struct('img', [], ...
- 'transform', 'axial', ...
- 'slicedef', [], ...
- 'slices', [], ...
- 'figure', [], ...
- 'figure_struct', [], ...
- 'refreshf', 1, ...
- 'clf', 1, ...
- 'resurrectf', 1, ...
- 'userdata', 1, ...
- 'area', [], ...
- 'xslices', [], ...
- 'cbar', [], ...
- 'labels', [], ...
- 'callback', ';', ...
- 'printstr', 'print -dpsc -painters -noui', ...
- 'printfile', 'slices.ps');
+ 'transform', 'axial', ...
+ 'slicedef', [], ...
+ 'slices', [], ...
+ 'figure', [], ...
+ 'figure_struct', [], ...
+ 'refreshf', 1, ...
+ 'clf', 1, ...
+ 'resurrectf', 1, ...
+ 'userdata', 1, ...
+ 'area', [], ...
+ 'xslices', [], ...
+ 'cbar', [], ...
+ 'labels', [], ...
+ 'callback', ';', ...
+ 'printstr', 'print -dpsc -painters -noui', ...
+ 'printfile', 'slices.ps');
if nargin < 1
- o = class(defstruct, myclass);
- others = [];
- return
+ o = class(defstruct, myclass);
+ others = [];
+ return
end
if nargin < 2
- others = [];
+ others = [];
end
% parse out string action calls (class functions)
if ischar(params)
- switch params
- case 'getcmap'
- if nargin < 2
- error('Need colormap name');
+ switch params
+ case 'getcmap'
+ if nargin < 2
+ error('Need colormap name');
+ end
+ o = pr_getcmap(others);
+ return
+ case 'volmaxmin'
+ if nargin < 2
+ error('Need volume to calculate max/min');
+ end
+ [o,others] = pr_volmaxmin(others);
+ return
+ case 'blobs2vol'
+ if nargin < 4
+ error('Need XYZ, vals, mat');
+ end
+ o = pr_blobs2vol(others, varargin{:});
+ return
+ case 'matrix2vol'
+ if nargin < 3
+ error('Need matrix and mat');
+ end
+ o = pr_matrix2vol(others, varargin{:});
+ return
+ case 'basic_ui'
+ o = pr_basic_ui(others, varargin{:});
+ if ~isempty(o), o = paint(o); end
+ return
end
- o = pr_getcmap(others);
- return
- case 'volmaxmin'
- if nargin < 2
- error('Need volume to calculate max/min');
- end
- [o others] = pr_volmaxmin(others);
- return
- case 'blobs2vol'
- if nargin < 4
- error('Need XYZ, vals, mat');
- end
- o = pr_blobs2vol(others, varargin{:});
- return
- case 'matrix2vol'
- if nargin < 3
- error('Need matrix and mat');
- end
- o = pr_matrix2vol(others, varargin{:});
- return
- case 'basic_ui'
- o = pr_basic_ui(others, varargin{:});
- if ~isempty(o), o = paint(o); end
- return
- end
-
- % if not action string, must be filename(s)
- params = spm_vol(params);
-end
+
+ % if not action string, must be filename(s)
+ params = spm_vol(params);
+end
% Could these just be image vol structs?
if isfield(params, 'fname')
- for i = 1:numel(params)
- obj.img(i).vol = params(i);
- end
- params = obj;
+ for i = 1:numel(params)
+ obj.img(i).vol = params(i);
+ end
+ params = obj;
end
% Deal with passed objects of this (or child) class
if isa(params, myclass)
- o = params;
- % Check for simple form of call
- if isempty(others), return, end
-
- % Otherwise, we are being asked to set fields of object
- [p others] = mars_struct('split', others, defstruct);
- o = mars_struct('ffillmerge', o, p);
- return
+ o = params;
+ % Check for simple form of call
+ if isempty(others), return, end
+
+ % Otherwise, we are being asked to set fields of object
+ [p,others] = mars_struct('split', others, defstruct);
+ o = mars_struct('ffillmerge', o, p);
+ return
end
% fill params with defaults, parse into fields for this object, children
@@ -243,5 +245,3 @@
% refill with defaults
o = fill_defaults(o);
-
-return
\ No newline at end of file
diff --git a/@slover/subsasgn.m b/@slover/subsasgn.m
index 77109d18..2c933fdb 100644
--- a/@slover/subsasgn.m
+++ b/@slover/subsasgn.m
@@ -1,7 +1,9 @@
function result = subsasgn(this, Struct, rhs)
-% method to overload . notation in assignments.
+% Method to overload . notation in assignments.
% . assignment works directly on object fields
-%
-% $Id: subsasgn.m,v 1.1 2005/04/20 15:05:36 matthewbrett Exp $
+%__________________________________________________________________________
+
+% Matthew Brett
+% $Id: subsasgn.m 6623 2015-12-03 18:38:08Z guillaume $
result = builtin('subsasgn', this, Struct, rhs);
diff --git a/@slover/subsref.m b/@slover/subsref.m
index 40a8fcbd..d3471363 100644
--- a/@slover/subsref.m
+++ b/@slover/subsref.m
@@ -1,7 +1,9 @@
function result = subsref(this, Struct)
-% method to overload the . notation.
+% Method to overload the . notation.
% . reference works directly on object fields
-%
-% $Id: subsref.m,v 1.1 2005/04/20 15:05:36 matthewbrett Exp $
+%__________________________________________________________________________
-result = builtin('subsref', this, Struct );
\ No newline at end of file
+% Matthew Brett
+% $Id: subsref.m 6623 2015-12-03 18:38:08Z guillaume $
+
+result = builtin('subsref', this, Struct );
diff --git a/@xmltree/Contents.m b/@xmltree/Contents.m
index 15f950ad..5caf714c 100644
--- a/@xmltree/Contents.m
+++ b/@xmltree/Contents.m
@@ -1,5 +1,5 @@
-% XMLTree: XML Toolbox for MATLAB.
-% Version 1.3 21-Apr-2008
+% XMLTree: XML Toolbox for MATLAB and GNU Octave
+% Version 1.4 13-Jun-2015
%
% XML file I/O.
% xmltree - Constructor (XML parser).
@@ -23,22 +23,21 @@
% parent - Return parents of a node.
% root - Return the root element of a tree.
% set - Set node properties.
-% setfilename - Set filename
+% setfilename - Set filename.
%
-% Graphical user interface methods (work in progress).
-% editor - Reimplementation of for MATLAB 6+
-% view - Graphical display of a tree.
-% view_ui - Useful function for view method.
+% Graphical user interface methods (basic).
+% editor - Graphical display of a tree.
+% view - (deprecated).
%
% Low level class methods.
% char - Convert a tree into a string (for display).
-% display - Display a tree into MATLAB.
+% display - Display a tree in the workspace.
%
% Private methods.
% xml_parser - XML parser.
-% xml_findstr - Find one string within another (mexfile)
+% xml_findstr - Find one string within another (C-MEX file).
%
-% Conversions MATLAB <=> XML
+% Conversions struct <=> XML.
% loadxml -
% savexml -
% mat2xml -
@@ -50,7 +49,7 @@
% xmldemo2 - Read an XML file and access fields.
% xmldemo3 - Read an XML file, modify some fields and save it.
-% Copyright 2002-2011 http://www.artefact.tk/
+% Copyright 2002-2015 http://www.artefact.tk/
% Guillaume Flandin
-% $Id: Contents.m 4460 2011-09-05 14:52:16Z guillaume $
+% $Id: Contents.m 6480 2015-06-13 01:08:30Z guillaume $
diff --git a/@xmltree/convert.m b/@xmltree/convert.m
index 7a783238..662a7018 100644
--- a/@xmltree/convert.m
+++ b/@xmltree/convert.m
@@ -1,5 +1,5 @@
function s = convert(tree,uid)
-% XMLTREE/CONVERT Converter an XML tree in a Matlab structure
+% XMLTREE/CONVERT Converter an XML tree in a structure
%
% tree - XMLTree object
% uid - uid of the root of the subtree, if provided.
@@ -7,21 +7,21 @@
% s - converted structure
%__________________________________________________________________________
%
-% Convert an xmltree into a Matlab structure, when possible.
+% Convert an XMLTree into a structure, when possible.
% When several identical tags are present, a cell array is used.
% The root tag is not saved in the structure.
% If provided, only the structure corresponding to the subtree defined
% by the uid UID is returned.
%__________________________________________________________________________
-% Copyright (C) 2002-2011 http://www.artefact.tk/
+% Copyright (C) 2002-2015 http://www.artefact.tk/
% Guillaume Flandin
-% $Id: convert.m 4460 2011-09-05 14:52:16Z guillaume $
+% $Id: convert.m 6480 2015-06-13 01:08:30Z guillaume $
% Exemple:
-% tree: field1field2field3
-% toto = convert(tree);
-% <=> toto = struct('titi',{{'field1', 'field3'}},'tutu','field2')
+% tree = 'field1field2field3';
+% toto = convert(xmltree(tree));
+% <=> toto = struct('b',{{'field1', 'field3'}},'c','field2')
%error(nargchk(1,2,nargin));
@@ -86,7 +86,7 @@
% end %-
case 'chardata'
s = sub_setfield(s,arg{:},get(tree,uid,'value'));
- %- convert strings into their Matlab equivalent when possible
+ %- convert strings into their numerical equivalent when possible
%- e.g. string '3.14159' becomes double scalar 3.14159
% v = get(tree,uid,'value'); %-
% cv = str2num(v); %-
@@ -113,7 +113,7 @@
try
s = sub_setfield(s,arg{:},feval(app,get(tree,uid,'value')));
catch
- warning('[XMLTREE] Unknown target application');
+ warning('[XMLTree] Unknown target application');
end
end
case 'comment'
diff --git a/@xmltree/copy.m b/@xmltree/copy.m
index d61cb385..9f9a1d91 100644
--- a/@xmltree/copy.m
+++ b/@xmltree/copy.m
@@ -7,13 +7,13 @@
% uid - UID of the element where the subtree must be duplicated
%__________________________________________________________________________
%
-% Copy a subtree to another branch
-% The tree parameter must be in input AND in output
+% Copy a subtree to another branch.
+% The tree parameter must be in input AND in output.
%__________________________________________________________________________
-% Copyright (C) 2002-2011 http://www.artefact.tk/
+% Copyright (C) 2002-2015 http://www.artefact.tk/
% Guillaume Flandin
-% $Id: copy.m 4460 2011-09-05 14:52:16Z guillaume $
+% $Id: copy.m 6480 2015-06-13 01:08:30Z guillaume $
%error(nargchk(2,3,nargin));
diff --git a/@xmltree/editor.m b/@xmltree/editor.m
index dccb6bca..0c82a0f4 100644
--- a/@xmltree/editor.m
+++ b/@xmltree/editor.m
@@ -1,17 +1,16 @@
function editor(tree)
%XMLTREE/EDITOR A Graphical User Interface for an XML tree
-% EDITOR(TREE) opens a new Matlab figure displaying the xmltree
-% object TREE.
+% EDITOR(TREE) opens a new figure displaying the xmltree object TREE.
% H = EDITOR(TREE) also returns the figure handle H.
%
% This is a beta version of successor
%
% See also XMLTREE
%__________________________________________________________________________
-% Copyright (C) 2002-2011 http://www.artefact.tk/
+% Copyright (C) 2002-2015 http://www.artefact.tk/
% Guillaume Flandin
-% $Id: editor.m 4460 2011-09-05 14:52:16Z guillaume $
+% $Id: editor.m 6524 2015-08-18 10:09:01Z guillaume $
%error(nargchk(1,1,nargin));
@@ -71,7 +70,7 @@ function editor(tree)
'Tag', 'xmllistbox');
%- Right box
-uicontrol('Style', 'list', ...
+uicontrol('Style', 'listbox', ...
'HorizontalAlignment','left', ...
'Units','Normalized', ...
'Visible','on',...
@@ -202,7 +201,7 @@ function doModify(fig,evd,h)
pos = get(handles.xmllistbox,'value');
uid = uidList(pos);
contents = children(tree,uid);
- if length(contents) > 0 & ...
+ if length(contents) > 0 && ...
strcmp(get(tree,contents(1),'type'),'chardata')
str = get(tree,contents(1),'value');
prompt = {'Name :','New value:'};
@@ -316,7 +315,7 @@ function doList(fig,evd,h)
%- Single mouse click
if strcmp(get(h,'SelectionType'),'normal')
contents = children(tree, uid);
- if length(contents) > 0 & ...
+ if length(contents) > 0 && ...
strcmp(get(tree,contents(1),'type'),'chardata')
str = get(tree,contents(1),'value');
set(handles.addbutton,'Enable','off');
@@ -360,7 +359,7 @@ function doUpdate(fig,evd,h)
function [batchString, uidList] = doUpdateR(tree, uid, o)
if nargin < 2, uid = root(tree); end
- if nargin < 3 | o == 0
+ if nargin < 3 || o == 0
o = 0;
sep = ' ';
else
@@ -374,7 +373,7 @@ function doUpdate(fig,evd,h)
uidList = [get(tree,uid,'uid')];
haselementchild = 0;
contents = get(tree, uid, 'contents');
- if isfield(tree, uid, 'show') & get(tree, uid, 'show') == 1
+ if isfield(tree, uid, 'show') && get(tree, uid, 'show') == 1
for i=1:length(contents)
if strcmp(get(tree,contents(i),'type'),'element')
[subbatchString, subuidList] = doUpdateR(tree,contents(i),o+1);
diff --git a/@xmltree/move.m b/@xmltree/move.m
index 1afe353b..a9613463 100644
--- a/@xmltree/move.m
+++ b/@xmltree/move.m
@@ -7,12 +7,12 @@
%__________________________________________________________________________
%
% Move a subtree inside a tree from A to B.
-% The tree parameter must be in input AND in output
+% The tree parameter must be in input AND in output.
%__________________________________________________________________________
-% Copyright (C) 2002-2011 http://www.artefact.tk/
+% Copyright (C) 2002-2015 http://www.artefact.tk/
% Guillaume Flandin
-% $Id: move.m 4460 2011-09-05 14:52:16Z guillaume $
+% $Id: move.m 6480 2015-06-13 01:08:30Z guillaume $
%error(nargchk(3,3,nargin));
diff --git a/@xmltree/private/xml_findstr.c b/@xmltree/private/xml_findstr.c
index 7a19e57e..1d5a0cf1 100644
--- a/@xmltree/private/xml_findstr.c
+++ b/@xmltree/private/xml_findstr.c
@@ -1,12 +1,12 @@
#include "mex.h"
/*
- * $Id: xml_findstr.c 4151 2011-01-07 18:09:25Z guillaume $
+ * $Id: xml_findstr.c 6480 2015-06-13 01:08:30Z guillaume $
* Guillaume Flandin
*/
/*
- Differences with matlab built-in findstr:
+ Differences with built-in findstr:
- allows to search only the n first occurences of a pattern
- allows to search only in a substring (given an index of the beginning)
@@ -14,8 +14,8 @@
- doesn't use mxGetString to prevent a copy of the string.
- assumes MATLAB stores strings as unsigned short (Unicode 16 bits)
matrix.h: typedef uint16_T mxChar;
- (that's the case for MATLAB 5.*, 6.* and 7.* but MATLAB 4.* stores strings
- as double and Octave as char, see src/mxarray.h)
+ (that's the case for MATLAB 5.*, 6.* and 7.* but MATLAB 4.* stores
+ strings as double and GNU Octave as char, see src/mxarray.h)
*/
/* Comment the following line to use standard mxGetString (slower) */
diff --git a/@xmltree/private/xml_findstr.mexw32 b/@xmltree/private/xml_findstr.mexw32
index 3a886c13..724484ef 100755
Binary files a/@xmltree/private/xml_findstr.mexw32 and b/@xmltree/private/xml_findstr.mexw32 differ
diff --git a/@xmltree/private/xml_findstr.mexw64 b/@xmltree/private/xml_findstr.mexw64
index 14f48248..b2baa9e0 100755
Binary files a/@xmltree/private/xml_findstr.mexw64 and b/@xmltree/private/xml_findstr.mexw64 differ
diff --git a/@xmltree/private/xml_parser.m b/@xmltree/private/xml_parser.m
index 5b31078c..61cf2b65 100644
--- a/@xmltree/private/xml_parser.m
+++ b/@xmltree/private/xml_parser.m
@@ -6,20 +6,20 @@
% tree - tree structure corresponding to the XML file
%__________________________________________________________________________
%
-% xml_parser.m is an XML 1.0 (http://www.w3.org/TR/REC-xml) parser
-% written in Matlab. It aims to be fully conforming. It is currently not
-% a validating XML processor.
+% xml_parser.m is an XML 1.0 (http://www.w3.org/TR/REC-xml) parser.
+% It aims to be fully conforming. It is currently not a validating
+% XML processor.
%
% A description of the tree structure provided in output is detailed in
% the header of this m-file.
%__________________________________________________________________________
-% Copyright (C) 2002-2011 http://www.artefact.tk/
+% Copyright (C) 2002-2015 http://www.artefact.tk/
% Guillaume Flandin
-% $Id: xml_parser.m 4460 2011-09-05 14:52:16Z guillaume $
+% $Id: xml_parser.m 6480 2015-06-13 01:08:30Z guillaume $
-% XML Processor for MATLAB (The Mathworks, Inc.).
-% Copyright (C) 2002-2011 Guillaume Flandin
+% XML Processor for GNU Octave and MATLAB (The Mathworks, Inc.)
+% Copyright (C) 2002-2015 Guillaume Flandin
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
@@ -44,14 +44,14 @@
%--------------------------------------------------------------------------
% The implementation of this XML parser is much inspired from a
-% Javascript parser available at
+% Javascript parser that used to be available at
-% A mex-file xml_findstr.c is also required, to encompass some
-% limitations of the built-in findstr Matlab function.
+% A C-MEX file xml_findstr.c is also required, to encompass some
+% limitations of the built-in FINDSTR function.
% Compile it on your architecture using 'mex -O xml_findstr.c' command
% if the compiled version for your system is not provided.
-% If this function behaves badly (crash or wrong results), comment the
-% line '#define __HACK_MXCHAR__' in xml_findstr.c and compile it again.
+% If this function does not behave as expected, comment the line
+% '#define __HACK_MXCHAR__' in xml_findstr.c and compile it again.
%--------------------------------------------------------------------------
% Structure of the output tree:
@@ -155,6 +155,7 @@
if isempty(TagStart)
%- Character data
error('[XML] Unknown data at the end of the XML file.');
+ Xparse_count = Xparse_count + 1;
xtree{Xparse_count} = chardata;
xtree{Xparse_count}.value = erode(entity(xmlstring(frag.str:end)));
xtree{Xparse_count}.parent = frag.parent;
@@ -166,6 +167,7 @@
frag.str = TagStart;
else
%- Character data
+ Xparse_count = Xparse_count + 1;
xtree{Xparse_count} = chardata;
xtree{Xparse_count}.value = erode(entity(xmlstring(frag.str:TagStart-1)));
xtree{Xparse_count}.parent = frag.parent;
@@ -224,6 +226,7 @@
name = starttag(1:nextspace-1);
attribs = starttag(nextspace+1:end);
end
+ Xparse_count = Xparse_count + 1;
xtree{Xparse_count} = element;
xtree{Xparse_count}.name = strip(name);
if frag.parent
@@ -253,6 +256,7 @@
warning('[XML] Tag opened but not closed.')
else
nextspace = xml_findstr(xmlstring,' ',frag.str,1);
+ Xparse_count = Xparse_count + 1;
xtree{Xparse_count} = pri;
if nextspace > close || nextspace == frag.str+2
xtree{Xparse_count}.value = erode(xmlstring(frag.str+2:close-1));
@@ -274,6 +278,7 @@
if isempty(close)
warning('[XML] Tag r%s %s\n', ...
- locRevs{locInd}, remRevs{inds(k)}, remFiles{inds(k)});
- end
- end
-
- if any(remoteDeleted)
- fprintf('\nthe following files are no longer part of FieldTrip:\n');
- files = locFiles(remoteDeleted);
- for k = 1:numel(files)
- fprintf(' %s\n', files{k});
- end
- end
-
- if any(remoteNew)
- fprintf('\nthe following new files are available:\n');
- files = remFiles(remoteNew);
- revs = remRevs(remoteNew);
- for k = 1:numel(files)
- fprintf(' r%sa %s\n', revs{k}, files{k});
- end
- end
-
- fprintf('\n');
-
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- case 'update'
- % get the remote changes, check that there are no conflicting local
- % changes and update the files
-
- if issvn
-
- fprintf('\nThis is an SVN working copy of FieldTrip, invoking ''svn update''...\n');
- olddir = pwd();
- cd(ftpath);
- system('svn update');
- cd(olddir);
- fprintf('\n');
-
- else
-
- % fetch remote hash table
- str = urlread(remotesignature);
- [remHashes, remFiles, remRevs] = parseHashTable(str);
-
- % fetch local hash table
- str = fileread(signaturefile);
- [locHashes, locFiles, locRevs] = parseHashTable(str);
-
- % determine changes
- [remoteDeleted, remoteNew, remoteChanges, localDeleted, localChanges] = findChanges(locHashes, locFiles, remHashes, remFiles, ftpath);
-
- % index all possible deletions and additions
- locFilesDelete = [];
- remFilesDownload = [];
-
- olddir = pwd();
- cd(ftpath);
-
- % keep track of whether local additions will possibly be overwritten
- overwriteFlag = 0;
-
- % first display information on what would be changed
- if any(remoteNew)
- fprintf('\nthe following new files will be added:\n');
- inds = find(remoteNew);
- for k = 1:numel(inds)
- if exist(remFiles{inds(k)}, 'file')
- msg = '!';
- overwriteFlag = 1;
- else
- msg = ' ';
- end
-
- % give this change a number and remember it
- remFilesDownload(end+1) = inds(k);
- locFilesDelete (end+1) = nan;
-
- fprintf('%s %3d. r%s %s\n', msg, numel(locFilesDelete), remRevs{inds(k)}, remFiles{inds(k)});
- end
- end
-
- if any(remoteDeleted)
- fprintf('\nthe following files will be deleted:\n');
- inds = find(remoteDeleted);
- for k = 1:numel(inds)
- if localChanges(inds(k))
- msg = '!';
- overwriteFlag = 1;
- else
- msg = ' ';
- end
-
- % give this change a number and remember it
- remFilesDownload(end+1) = nan;
- locFilesDelete (end+1) = inds(k);
-
- fprintf('%s %3d. %s\n', msg, numel(locFilesDelete), locFiles{inds(k)});
- end
- end
-
- if any(remoteChanges)
- fprintf('\nthe following files will be updated:\n');
- inds = find(remoteChanges);
- for k = 1:numel(inds)
- locInd = strcmp(locFiles, remFiles{inds(k)});
- if localChanges(locInd)
- msg = '!';
- overwriteFlag = 1;
- else
- msg = ' ';
- end
-
- % give this change a number and remember it
- remFilesDownload(end+1) = inds(k);
- locFilesDelete (end+1) = nan;
-
- fprintf('%s %3d. r%s-->r%s %s\n', msg, numel(locFilesDelete), locRevs{locInd}, remRevs{inds(k)}, remFiles{inds(k)});
- end
- end
-
- assert(numel(remFilesDownload) == numel(locFilesDelete));
-
- if overwriteFlag
- fprintf(['\n!!NOTE: if you choose to include changes marked with a leading !, \n'...
- ' they will overwrite local changes or additions!\n']);
- end
-
- % prompt the user which changes should be incorporated
- while (true) % use while (true) as poor man's do{}while()
- changesToInclude = input(['\nwhich changes do you want to include?\n'...
- '([vector] for specific changes, ''all'', or [] for none)\n? '], 's');
-
- % check integrity of entered data
- if strcmp(changesToInclude, 'all')
- changesToInclude = 1:numel(remFilesDownload);
- else
- [changesToInclude, status] = str2num(changesToInclude);
- end
-
- if status && isnumeric(changesToInclude) && all(changesToInclude > 0) && (all(changesToInclude <= numel(remFilesDownload)) || changesToInclude == Inf)
- changesToInclude = unique(changesToInclude);
- break;
- end
- end
-
- % include only those changes requested in the actual update
- locFilesDelete = locFilesDelete(changesToInclude);
- locFilesDelete(isnan(locFilesDelete)) = [];
- remFilesDownload = remFilesDownload(changesToInclude);
- remFilesDownload(isnan(remFilesDownload)) = [];
-
- % delete all local files that should be deleted
- for k = 1:numel(locFilesDelete)
- ind = locFilesDelete(k);
- fprintf('deleting file %s...\n', locFiles{ind});
- delete(locFiles{ind});
- % also remove entry from the hash table cell arrays
- locFiles(ind) = [];
- locHashes(ind) = [];
- locRevs(ind) = [];
- end
-
- % add new files and/or update changed files
- for k = 1:numel(remFilesDownload)
- ind = remFilesDownload(k);
- fprintf('downloading file %s...\n', remFiles{ind});
- newFile = urlread([repository remFiles{ind}]);
- fp = fopen(remFiles{ind}, 'w');
- fwrite(fp, newFile);
- fclose(fp);
-
- % update local hash table
- locInd = strcmp(locFiles, remFiles{ind});
- if any(locInd)
- % file was already present, update hash
- locHashes{locInd} = remHashes{ind};
- locRevs{locInd} = remRevs{ind};
- else
- % new file, add hash
- locFiles{end} = remFiles{ind};
- locHashes{end} = remHashes{ind};
- locRevs{end} = remRevs{ind};
- end
-
- end
-
- cd(olddir);
-
- if ~isempty(changesToInclude)
- % output new hash table
- fp = fopen(signaturefile, 'w');
- outputHashTable(fp, locHashes, locFiles, locRevs);
- fclose(fp);
-
- fprintf('update finished.\n');
- else
- fprintf('nothing updated.\n');
- end
-
- ft_version();
-
- end
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- case 'signature'
-
- if exist(signaturefile, 'file')
- error('%s already exists.\nIf you are sure you want to re-create the signature file, you will have to manually delete it.\nNote that this means that local edits cannot be tracked anymore, and might be overwritten without notice!', signaturefile);
- end
-
- fprintf('\nwriting signature file to signature-local.md5 (this might take a few minutes)...');
- hashFile = fopen(signaturefile, 'w');
- hashAll(hashFile, ftpath, ftpath);
- fclose(hashFile);
- fprintf('done.\n\n');
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- case 'fullsignature'
-
- if exist(signaturefile, 'file')
- error('%s already exists.\nIf you are sure you want to re-create the signature file, you will have to manually delete it.\nNote that this means that local edits cannot be tracked anymore, and might be overwritten without notice!', signaturefile);
- end
-
- if ~issvn
- error('you can only generate a full signature with revision info if you are using an SVN working copy of FieldTrip');
- end
-
- fprintf('\nwriting signature file to signature-local.md5 (this might take a few minutes)...');
- hashFile = fopen(fullfile(ftpath, 'signature-local.md5'), 'w');
- hashAll(hashFile, ftpath, ftpath, 1);
- fclose(hashFile);
- fprintf('done.\n\n');
-
-end % switch cmd
-
-end % function ft_version
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-function [remoteDeleted, remoteNew, remoteChanges, localDeleted, localChanges] = findChanges(locHashes, locFiles, remHashes, remFiles, ftpath)
-% locHashes and locFiles represent the hashes and filenames of entries in
-% the local hash table, respectively. remHashes and remFiles represent the
-% hashes and filenames of entries in the remote hash table, respectively.
-% ftpath is the FT root path. Returned are logical index vectors into the
-% remFiles cell array (for remoteChanges and remoteNew) or into the
-% locFiles cell array (rest).
-
-fprintf('\ncomparing local and remote (latest) hashes, this might take a minute...\n');
-
-remoteDeleted = false(size(locFiles));
-localChanges = false(size(locFiles));
-remoteChanges = false(size(remFiles));
-localDeleted = false(size(locFiles));
-% note: no keeping track of local additions (not desirable probably)
-
-% compare them by looping over all files in local table
-for k = 1:numel(locFiles)
- ind = strcmp(remFiles, locFiles{k});
-
- if sum(ind) > 1
- % this should never happen; means remote table is corrupt
- warning('more than one entry found in remote hash table for file %s', locFiles{k});
- end
-
- if ~any(ind)
- % file not found in remote table, should be deleted locally
- remoteDeleted(k) = 1;
- continue;
- end
-
- if ~strcmp(remHashes{ind}, locHashes{k})
- % hash remote different from hash in local table
- remoteChanges(ind) = 1;
- end
-
- if ~exist(fullfile(ftpath, locFiles{k}), 'file')
- localDeleted(k) = 1;
- continue;
- end
-
- if (nargout > 4) % only check for local changes if requested, slow step
- if ~strcmp(CalcMD5(fullfile(ftpath, locFiles{k}), 'File'), locHashes{k})
- % hash of actual file different from hash in local table
- localChanges(k) = 1;
- end
- end
-end
-
-% only remote additions have not yet been determined, do so now
-remoteNew = false(size(remFiles));
-[dummy, inds] = setdiff(remFiles, locFiles);
-remoteNew(inds) = 1;
-
-end % function findChanges
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-function [hashes, files, revs] = parseHashTable(str)
-% If str is a tab-separated string, with records separated by newlines,
-% parseHashTable(str) will return the three columns in the file: the first
-% column will be returned as hashes; the second as revs, the third as
-% files.
-
-lines = regexp(str, '\n', 'split');
-if isempty(lines{end})
- lines = lines(1:end-1);
+if isempty(isgit)
+ % are we dealing with an GIT working copy of fieldtrip?
+ isgit = isdir(fullfile(ftpath, '.git'));
end
-hashes = cell(1, numel(lines));
-files = cell(1, numel(lines));
-revs = cell(1, numel(lines));
-
-for k = 1:numel(lines)
- tmp = regexp(lines{k}, '\t', 'split');
- hashes{k} = tmp{1};
- revs{k} = tmp{2};
- files{k} = tmp{3};
-end
-
-end % function parseHashTable
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-function hashAll(filePointer, path, basepath, withRev)
-
-if nargin < 4
- withRev = 0;
-end
-
-% these files are always excluded from the update and hashing routines
-file_excludes = {'.', '..', '.svn', 'test', '.DS_Store', 'signature.md5', 'signature-local.md5'};
-
-list = dir(path);
-for k = 1:numel(list)
- if ~any(strcmp(list(k).name, file_excludes))
- filename = [path '/' list(k).name];
- if (list(k).isdir)
- hashAll(filePointer, filename, basepath, withRev);
- else
- md5 = CalcMD5(filename, 'File');
-
- if withRev
- [status, output] = system(['svn info ' filename]);
- rev = regexp(output, 'Last Changed Rev: (.*)', 'tokens', 'dotexceptnewline');
- if ~isempty(rev) && ~isempty(rev{1})
- rev = rev{1}{1};
- else
- rev = 'UNKNOWN';
- end
- else
- rev = 'UNKNOWN';
- end
- filename = filename((numel(basepath)+2):end); % strip off the base path
- fprintf(filePointer, '%s\t%s\t%s\n', md5, rev, filename);
+% show the latest revision present in this copy of fieldtrip
+
+if issvn
+ % use svn system call to determine latest revision
+ olddir = pwd();
+ cd(ftpath);
+ [status, output] = system('svn info');
+ cd(olddir);
+ if status > 0
+ if ~ispc
+ % the command line tools will probably not be available on windows
+ warning('you seem to have an SVN development copy of FieldTrip, yet ''svn info'' does not work as expected');
end
+ ftver = 'unknown';
+ else
+ rev = regexp(output, 'Revision: (.*)', 'tokens', 'dotexceptnewline');
+ rev = rev{1}{1};
+ ftver = ['r' rev];
end
-end
-end % function hashAll
+elseif isgit
+ tmpfile = tempname;
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ olddir = pwd();
+ cd(ftpath);
+ [status, output] = system(sprintf('git show > %s', tmpfile));
+ cd(olddir);
+ if status > 0
+ % FIXME the command line tools will probably not be available on windows
+ error('you seem to have an GIT development copy of FieldTrip, yet ''git show'' does not work as expected');
+ end
-function outputHashTable(filePointer, hashes, files, revs)
+ fp = fopen(tmpfile);
+ if fp>0
+ line = fgetl(fp); % the first line contains the commit number
+ fclose(fp);
+ rev = regexp(line, ' ', 'split');
+ rev = rev{2};
+
+ % this is a string like 4d3c309129f12146885120c2853a11362e048ea7
+ ftver = rev;
+ else
+ ftver = 'unknown';
+ end
-% sort the entries (highest revs should always be at the top)
-numRevs = cellfun(@str2double, revs);
-[sortedRevs, inds] = sort(numRevs, 'descend');
-lastnan = find(isnan(sortedRevs), 1, 'last'); % put nans (=UNKNOWN) at the end
-inds = [inds(lastnan+1:end) inds(1:lastnan)];
+else
+ % get it from the Contents.m file in the FieldTrip release
+ a = ver(ftpath);
+ ftver = a.Version;
-hashes = hashes(inds);
-files = files(inds);
-revs = revs(inds);
+end % if issvn, isgit or otherwise
-for k = 1:numel(hashes)
- fprintf(filePointer, '%s\t%s\t%s\n', hashes{k}, revs{k}, files{k});
+if nargout==0
+ fprintf('\nThis is FieldTrip, version %s.\n\n', ftver);
+ clear ftver
end
-
-end % function outputHashTable
diff --git a/external/fieldtrip/utilities/ft_warning.m b/external/fieldtrip/utilities/ft_warning.m
new file mode 100644
index 00000000..03286e95
--- /dev/null
+++ b/external/fieldtrip/utilities/ft_warning.m
@@ -0,0 +1,258 @@
+function [ws, warned] = ft_warning(varargin)
+
+% FT_WARNING will throw a warning for every unique point in the
+% stacktrace only, e.g. in a for-loop a warning is thrown only once.
+%
+% Use as one of the following
+% ft_warning(string)
+% ft_warning(id, string)
+% Alternatively, you can use ft_warning using a timeout
+% ft_warning(string, timeout)
+% ft_warning(id, string, timeout)
+% where timeout should be inf if you don't want to see the warning ever
+% again.
+%
+% Use as ft_warning('-clear') to clear old warnings from the current
+% stack
+%
+% It can be used instead of the MATLAB built-in function WARNING, thus as
+% s = ft_warning(...)
+% or as
+% ft_warning(s)
+% where s is a structure with fields 'identifier' and 'state', storing the
+% state information. In other words, ft_warning accepts as an input the
+% same structure it returns as an output. This returns or restores the
+% states of warnings to their previous values.
+%
+% It can also be used as
+% [s w] = ft_warning(...)
+% where w is a boolean that indicates whether a warning as been thrown or not.
+%
+% Please note that you can NOT use it like this
+% ft_warning('the value is %d', 10)
+% instead you should do
+% ft_warning(sprintf('the value is %d', 10))
+
+% Copyright (C) 2012, Robert Oostenveld
+% Copyright (C) 2013, Robert Oostenveld, J?rn M. Horschig
+%
+% This file is part of FieldTrip, see http://www.ru.nl/neuroimaging/fieldtrip
+% for the documentation and details.
+%
+% FieldTrip is free software: you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation, either version 3 of the License, or
+% (at your option) any later version.
+%
+% FieldTrip is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU General Public License
+% along with FieldTrip. If not, see .
+%
+% $Id: ft_warning.m 10531 2015-07-13 14:11:06Z roboos $
+
+global ft_default
+
+if nargin < 1
+ error('You need to specify at least a warning message');
+end
+
+warned = false;
+if isstruct(varargin{1})
+ warning(varargin{1});
+ return;
+end
+
+if ~isfield(ft_default, 'warning')
+ ft_default.warning = [];
+end
+if ~isfield(ft_default.warning, 'stopwatch')
+ ft_default.warning.stopwatch = [];
+end
+if ~isfield(ft_default.warning, 'identifier')
+ ft_default.warning.identifier = [];
+end
+if ~isfield(ft_default.warning, 'ignore')
+ ft_default.warning.ignore = {};
+end
+
+% put the arguments we will pass to warning() in this cell array
+warningArgs = {};
+
+if nargin==3
+ % calling syntax (id, msg, timeout)
+
+ warningArgs = varargin(1:2);
+ msg = warningArgs{2};
+ timeout = varargin{3};
+ fname = [warningArgs{1} '_' warningArgs{2}];
+
+elseif nargin==2 && isnumeric(varargin{2})
+ % calling syntax (msg, timeout)
+
+ warningArgs = varargin(1);
+ msg = warningArgs{1};
+ timeout = varargin{2};
+ fname = warningArgs{1};
+
+elseif nargin==2 && isequal(varargin{1}, 'off')
+
+ ft_default.warning.ignore = union(ft_default.warning.ignore, varargin{2});
+ return
+
+elseif nargin==2 && isequal(varargin{1}, 'on')
+
+ ft_default.warning.ignore = setdiff(ft_default.warning.ignore, varargin{2});
+ return
+
+elseif nargin==2 && ~isnumeric(varargin{2})
+ % calling syntax (id, msg)
+
+ warningArgs = varargin(1:2);
+ msg = warningArgs{2};
+ timeout = inf;
+ fname = [warningArgs{1} '_' warningArgs{2}];
+
+elseif nargin==1
+ % calling syntax (msg)
+
+ warningArgs = varargin(1);
+ msg = warningArgs{1};
+ timeout = inf; % default timeout in seconds
+ fname = [warningArgs{1}];
+
+end
+
+if ismember(msg, ft_default.warning.ignore)
+ % do not show this warning
+ return;
+end
+
+if isempty(timeout)
+ error('Timeout ill-specified');
+end
+
+if timeout ~= inf
+ fname = decomma(fixname(fname)); % make a nice string that is allowed as structure fieldname
+ if length(fname) > 63 % MATLAB max name
+ fname = fname(1:63);
+ end
+ line = [];
+else
+ % here, we create the fieldname functionA.functionB.functionC...
+ [tmpfname ft_default.warning.identifier line] = fieldnameFromStack(ft_default.warning.identifier);
+ if ~isempty(tmpfname)
+ fname = tmpfname;
+ clear tmpfname;
+ end
+end
+
+if nargin==1 && ischar(varargin{1}) && strcmp('-clear', varargin{1})
+ if strcmp(fname, '-clear') % reset all fields if called outside a function
+ ft_default.warning.identifier = [];
+ ft_default.warning.stopwatch = [];
+ else
+ if issubfield(ft_default.warning.identifier, fname)
+ ft_default.warning.identifier = rmsubfield(ft_default.warning.identifier, fname);
+ end
+ end
+ return;
+end
+
+% and add the line number to make this unique for the last function
+fname = horzcat(fname, line);
+
+if ~issubfield('ft_default.warning.stopwatch', fname)
+ ft_default.warning.stopwatch = setsubfield(ft_default.warning.stopwatch, fname, tic);
+end
+
+now = toc(getsubfield(ft_default.warning.stopwatch, fname)); % measure time since first function call
+
+if ~issubfield(ft_default.warning.identifier, fname) || ...
+ (issubfield(ft_default.warning.identifier, fname) && now>getsubfield(ft_default.warning.identifier, [fname '.timeout']))
+
+ % create or reset field
+ ft_default.warning.identifier = setsubfield(ft_default.warning.identifier, fname, []);
+
+ % warning never given before or timed out
+ ws = warning(warningArgs{:});
+ ft_default.warning.identifier = setsubfield(ft_default.warning.identifier, [fname '.timeout'], now+timeout);
+ ft_default.warning.identifier = setsubfield(ft_default.warning.identifier, [fname '.ws'], msg);
+ warned = true;
+else
+
+ % the warning has been issued before, but has not timed out yet
+ ws = getsubfield(ft_default.warning.identifier, [fname '.ws']);
+
+end
+
+end % function ft_warning
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% helper functions
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function name = decomma(name)
+name(name==',')=[];
+end % function
+
+function [fname ft_previous_warnings line] = fieldnameFromStack(ft_previous_warnings)
+% stack(1) is this function, stack(2) is ft_warning
+stack = dbstack('-completenames');
+if size(stack) < 3
+ fname = [];
+ line = [];
+ return;
+end
+i0 = 3;
+% ignore ft_preamble
+while strfind(stack(i0).name, 'ft_preamble')
+ i0=i0+1;
+end
+
+fname = horzcat(fixname(stack(end).name));
+if ~issubfield(ft_previous_warnings, fixname(stack(end).name))
+ ft_previous_warnings.(fixname(stack(end).name)) = []; % iteratively build up structure fields
+end
+
+
+for i=numel(stack)-1:-1:(i0)
+ % skip postamble scripts
+ if strncmp(stack(i).name, 'ft_postamble', 12)
+ break;
+ end
+
+ fname = horzcat(fname, '.', horzcat(fixname(stack(i).name))); % , stack(i).file
+ if ~issubfield(ft_previous_warnings, fname) % iteratively build up structure fields
+ setsubfield(ft_previous_warnings, fname, []);
+ end
+end
+
+% line of last function call
+line = ['.line', int2str(stack(i0).line)];
+end
+
+% function outcome = issubfield(strct, fname)
+% substrindx = strfind(fname, '.');
+% if numel(substrindx) > 0
+% % separate the last fieldname from all former
+% outcome = eval(['isfield(strct.' fname(1:substrindx(end)-1) ', ''' fname(substrindx(end)+1:end) ''')']);
+% else
+% % there is only one fieldname
+% outcome = isfield(strct, fname);
+% end
+% end
+
+% function strct = rmsubfield(strct, fname)
+% substrindx = strfind(fname, '.');
+% if numel(substrindx) > 0
+% % separate the last fieldname from all former
+% strct = eval(['rmfield(strct.' fname(1:substrindx(end)-1) ', ''' fname(substrindx(end)+1:end) ''')']);
+% else
+% % there is only one fieldname
+% strct = rmfield(strct, fname);
+% end
+% end
diff --git a/external/fieldtrip/utilities/ft_warp_apply.m b/external/fieldtrip/utilities/ft_warp_apply.m
index 2e60649e..88005c27 100644
--- a/external/fieldtrip/utilities/ft_warp_apply.m
+++ b/external/fieldtrip/utilities/ft_warp_apply.m
@@ -70,7 +70,7 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: ft_warp_apply.m 10131 2015-01-27 16:08:26Z johzum $
+% $Id: ft_warp_apply.m 11052 2016-01-09 17:51:12Z roboos $
if nargin<4
tol = [];
@@ -163,13 +163,13 @@
M(3,1) M(3,2) 0 M(3,3)
];
end
-
+
%warped = M * [input'; ones(1, size(input, 1))];
%warped = warped(1:3,:)';
-
+
% below achieves the same as lines 154-155
warped = [input ones(size(input, 1),1)]*M(1:3,:)';
-
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% using external function that returns a homogeneous transformation matrix
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/external/fieldtrip/utilities/ft_warp_error.m b/external/fieldtrip/utilities/ft_warp_error.m
index 73949231..83648e2b 100644
--- a/external/fieldtrip/utilities/ft_warp_error.m
+++ b/external/fieldtrip/utilities/ft_warp_error.m
@@ -4,11 +4,11 @@
% and can be used as the goalfunction in a 3D warping minimalisation
%
% Use as
-% [dist] = ft_warp_error(M, input, target, 'method')
+% dist = ft_warp_error(M, input, target, 'method')
%
-% It returns the mean Euclidian distance (residu) when attempting to
-% transform the input towards the target using transformation M
-% and using the specified warping method.
+% It returns the mean Euclidian distance (i.e. the residual) for an interative
+% optimalization to transform the input towards the target using the
+% transformation M with the specified warping method.
%
% See also FT_WARP_OPTIM, FT_WARP_APPLY
@@ -44,7 +44,7 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: ft_warp_error.m 8756 2013-11-11 12:53:49Z roboos $
+% $Id: ft_warp_error.m 11052 2016-01-09 17:51:12Z roboos $
if ~isempty(M)
% apply the warp to the input positions
@@ -78,4 +78,3 @@
dif = input - target;
dist = mean(sqrt(sum(dif' .^2)));
end
-
diff --git a/external/fieldtrip/utilities/hasyokogawa.m b/external/fieldtrip/utilities/hasyokogawa.m
index fa0c7516..09c0f321 100644
--- a/external/fieldtrip/utilities/hasyokogawa.m
+++ b/external/fieldtrip/utilities/hasyokogawa.m
@@ -5,7 +5,7 @@
% installed. Only the newest version of the toolbox is accepted.
%
% Use as
-% [string] = hasyokogawa;
+% string = hasyokogawa;
% which returns a string describing the toolbox version, e.g. "12bitBeta3",
% "16bitBeta3", or "16bitBeta6" for preliminary versions, or '1.4' for the
% official Yokogawa MEG Reader Toolbox. An empty string is returned if the toolbox
@@ -37,7 +37,7 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: hasyokogawa.m 10398 2015-05-08 15:56:53Z tilsan $
+% $Id: hasyokogawa.m 11052 2016-01-09 17:51:12Z roboos $
ws = warning('off', 'MATLAB:pfileOlderThanMfile');
@@ -54,7 +54,7 @@
elseif exist('GetMeg160ADbitInfoM') || exist('GetMeg160ChannelInfoM') || exist('GetMeg160ContinuousRawDataM')
% start with unknown, try to refine the version
version = 'unknown';
-
+
try
% Call some functions with input argument "Inf": If
% the functions are present they return their revision number.
@@ -85,7 +85,7 @@
end
end
end
-
+
else
% return empty if none of them is present
version = [];
@@ -95,7 +95,7 @@
% return a true/false value
if isempty(version)
version = false;
- else
+ else
version = strcmpi(version, desired);
end
end
diff --git a/external/fieldtrip/utilities/nearest.m b/external/fieldtrip/utilities/nearest.m
index 534efe1a..0cffba6a 100644
--- a/external/fieldtrip/utilities/nearest.m
+++ b/external/fieldtrip/utilities/nearest.m
@@ -22,6 +22,8 @@
% return an error, but nearest(1:10, 0.99, true, true) will return 1. The
% tolerance that is allowed is half the distance between the subsequent
% values in the array.
+%
+% See also FIND
% Copyright (C) 2002-2012, Robert Oostenveld
%
@@ -41,7 +43,7 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: nearest.m 10137 2015-01-28 11:19:58Z roboos $
+% $Id: nearest.m 11052 2016-01-09 17:51:12Z roboos $
mbreal(array);
mbreal(val);
@@ -122,11 +124,11 @@
% return the last occurence of the largest number
[dum, indx] = max(flipud(array));
indx = numel(array) + 1 - indx;
-
+
elseif val=val, 1, 'first');
if abs(array(indx2)-val) <= abs(array(indx3)-val)
@@ -156,7 +158,7 @@
if ~wassorted
indx = xidx(indx);
end
-
+
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -182,4 +184,3 @@ function mbvector(a)
if ndims(a) > 2 || (size(a, 1) > 1 && size(a, 2) > 1)
error('Argument to mbvector must be a vector');
end
-
diff --git a/external/fieldtrip/utilities/printstruct.m b/external/fieldtrip/utilities/printstruct.m
index b0382d30..7ad997b9 100644
--- a/external/fieldtrip/utilities/printstruct.m
+++ b/external/fieldtrip/utilities/printstruct.m
@@ -20,6 +20,8 @@
% s = printstruct(b)
%
% s = printstruct('c', randn(10)>0.5)
+%
+% See also DISP
% Copyright (C) 2006-2013, Robert Oostenveld
%
@@ -39,7 +41,7 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: printstruct.m 10030 2014-12-09 15:22:51Z eelspa $
+% $Id: printstruct.m 11052 2016-01-09 17:51:12Z roboos $
if nargin==1
val = name;
@@ -131,7 +133,7 @@
dum = [dum ' ' printval(val{i,j}) ',']; % add the element with a comma
end
dum = [dum ' ' printval(val{i,siz(2)})]; % add the last one without comma
-
+
str = [str dum 10];
end
str = sprintf('%s};\n', str);
@@ -177,17 +179,17 @@
switch class(val)
case 'char'
str = ['''' val ''''];
-
+
case {'single' 'double' 'int8' 'int16' 'int32' 'int64' 'uint8' 'uint16' 'uint32' 'uint64' 'logical'}
str = printmat(val);
-
+
case 'function_handle'
str = ['@' func2str(val)];
-
+
case 'struct'
warning('cannot print structure at this level');
str = '''FIXME: printing structures at this level is not supported''';
-
+
otherwise
warning('cannot print unknown object at this level');
str = '''FIXME: printing unknown objects is not supported''';
diff --git a/external/fieldtrip/utilities/private/base64encode.m b/external/fieldtrip/utilities/private/base64encode.m
new file mode 100644
index 00000000..026c0a92
--- /dev/null
+++ b/external/fieldtrip/utilities/private/base64encode.m
@@ -0,0 +1,159 @@
+function y = base64encode(x, eol)
+%BASE64ENCODE Perform base64 encoding on a string.
+%
+% BASE64ENCODE(STR, EOL) encode the given string STR. EOL is the line ending
+% sequence to use; it is optional and defaults to '\n' (ASCII decimal 10).
+% The returned encoded string is broken into lines of no more than 76
+% characters each, and each line will end with EOL unless it is empty. Let
+% EOL be empty if you do not want the encoded string broken into lines.
+%
+% STR and EOL don't have to be strings (i.e., char arrays). The only
+% requirement is that they are vectors containing values in the range 0-255.
+%
+% This function may be used to encode strings into the Base64 encoding
+% specified in RFC 2045 - MIME (Multipurpose Internet Mail Extensions). The
+% Base64 encoding is designed to represent arbitrary sequences of octets in a
+% form that need not be humanly readable. A 65-character subset
+% ([A-Za-z0-9+/=]) of US-ASCII is used, enabling 6 bits to be represented per
+% printable character.
+%
+% Examples
+% --------
+%
+% If you want to encode a large file, you should encode it in chunks that are
+% a multiple of 57 bytes. This ensures that the base64 lines line up and
+% that you do not end up with padding in the middle. 57 bytes of data fills
+% one complete base64 line (76 == 57*4/3):
+%
+% If ifid and ofid are two file identifiers opened for reading and writing,
+% respectively, then you can base64 encode the data with
+%
+% while ~feof(ifid)
+% fwrite(ofid, base64encode(fread(ifid, 60*57)));
+% end
+%
+% or, if you have enough memory,
+%
+% fwrite(ofid, base64encode(fread(ifid)));
+%
+% See also BASE64DECODE.
+
+% Author: Peter J. Acklam
+% Time-stamp: 2004-02-03 21:36:56 +0100
+% E-mail: pjacklam@online.no
+% URL: http://home.online.no/~pjacklam
+
+ % check number of input arguments
+ error(nargchk(1, 2, nargin));
+
+ % make sure we have the EOL value
+ if nargin < 2
+ eol = ''; %sprintf('\n');
+ else
+ if sum(size(eol) > 1) > 1
+ error('EOL must be a vector.');
+ end
+ if any(eol(:) > 255)
+ error('EOL can not contain values larger than 255.');
+ end
+ end
+
+ if sum(size(x) > 1) > 1
+ error('STR must be a vector.');
+ end
+
+ x = uint8(x);
+ eol = uint8(eol);
+
+ ndbytes = length(x); % number of decoded bytes
+ nchunks = ceil(ndbytes / 3); % number of chunks/groups
+ nebytes = 4 * nchunks; % number of encoded bytes
+
+ % add padding if necessary, to make the length of x a multiple of 3
+ if rem(ndbytes, 3)
+ x(end+1 : 3*nchunks) = 0;
+ end
+
+ x = reshape(x, [3, nchunks]); % reshape the data
+ y = repmat(uint8(0), 4, nchunks); % for the encoded data
+
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ % Split up every 3 bytes into 4 pieces
+ %
+ % aaaaaabb bbbbcccc ccdddddd
+ %
+ % to form
+ %
+ % 00aaaaaa 00bbbbbb 00cccccc 00dddddd
+ %
+ y(1,:) = bitshift(x(1,:), -2); % 6 highest bits of x(1,:)
+
+ y(2,:) = bitshift(bitand(x(1,:), 3), 4); % 2 lowest bits of x(1,:)
+ y(2,:) = bitor(y(2,:), bitshift(x(2,:), -4)); % 4 highest bits of x(2,:)
+
+ y(3,:) = bitshift(bitand(x(2,:), 15), 2); % 4 lowest bits of x(2,:)
+ y(3,:) = bitor(y(3,:), bitshift(x(3,:), -6)); % 2 highest bits of x(3,:)
+
+ y(4,:) = bitand(x(3,:), 63); % 6 lowest bits of x(3,:)
+
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ % Now perform the following mapping
+ %
+ % 0 - 25 -> A-Z
+ % 26 - 51 -> a-z
+ % 52 - 61 -> 0-9
+ % 62 -> +
+ % 63 -> /
+ %
+ % We could use a mapping vector like
+ %
+ % ['A':'Z', 'a':'z', '0':'9', '+/']
+ %
+ % but that would require an index vector of class double.
+ %
+ z = repmat(uint8(0), size(y));
+ i = y <= 25; z(i) = 'A' + double(y(i));
+ i = 26 <= y & y <= 51; z(i) = 'a' - 26 + double(y(i));
+ i = 52 <= y & y <= 61; z(i) = '0' - 52 + double(y(i));
+ i = y == 62; z(i) = '+';
+ i = y == 63; z(i) = '/';
+ y = z;
+
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ % Add padding if necessary.
+ %
+ npbytes = 3 * nchunks - ndbytes; % number of padding bytes
+ if npbytes
+ y(end-npbytes+1 : end) = '='; % '=' is used for padding
+ end
+
+ if isempty(eol)
+
+ % reshape to a row vector
+ y = reshape(y, [1, nebytes]);
+
+ else
+
+ nlines = ceil(nebytes / 76); % number of lines
+ neolbytes = length(eol); % number of bytes in eol string
+
+ % pad data so it becomes a multiple of 76 elements
+ y(nebytes + 1 : 76 * nlines) = 0;
+ y = reshape(y, 76, nlines);
+
+ % insert eol strings
+ eol = eol(:);
+ y(end + 1 : end + neolbytes, :) = eol(:, ones(1, nlines));
+
+ % remove padding, but keep the last eol string
+ m = nebytes + neolbytes * (nlines - 1);
+ n = (76+neolbytes)*nlines - neolbytes;
+ y(m+1 : n) = '';
+
+ % extract and reshape to row vector
+ y = reshape(y, 1, m+neolbytes);
+
+ end
+
+ % output is a character array
+ y = char(y);
diff --git a/external/fieldtrip/utilities/private/dataset2files.m b/external/fieldtrip/utilities/private/dataset2files.m
index dce9ecc6..a407a4bf 100644
--- a/external/fieldtrip/utilities/private/dataset2files.m
+++ b/external/fieldtrip/utilities/private/dataset2files.m
@@ -24,7 +24,7 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: dataset2files.m 10381 2015-05-07 07:31:10Z roboos $
+% $Id: dataset2files.m 10624 2015-08-24 21:13:37Z roboos $
persistent previous_argin previous_argout
@@ -99,12 +99,14 @@
case 'brainvision_vhdr'
[path, file, ext] = fileparts(filename);
headerfile = fullfile(path, [file '.vhdr']);
- if exist(fullfile(path, [file '.eeg']))
+ if exist(fullfile(path, [file '.eeg']), 'file')
datafile = fullfile(path, [file '.eeg']);
- elseif exist(fullfile(path, [file '.seg']))
+ elseif exist(fullfile(path, [file '.seg']), 'file')
datafile = fullfile(path, [file '.seg']);
- elseif exist(fullfile(path, [file '.dat']))
+ elseif exist(fullfile(path, [file '.dat']), 'file')
datafile = fullfile(path, [file '.dat']);
+ else
+ error('cannot determine the data file that corresponds to %s', filename);
end
case 'brainvision_eeg'
[path, file, ext] = fileparts(filename);
diff --git a/external/fieldtrip/utilities/private/fixdimord.m b/external/fieldtrip/utilities/private/fixdimord.m
index c2b82bbb..a760e280 100644
--- a/external/fieldtrip/utilities/private/fixdimord.m
+++ b/external/fieldtrip/utilities/private/fixdimord.m
@@ -44,7 +44,7 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: fixdimord.m 9972 2014-11-19 08:09:34Z roboos $
+% $Id: fixdimord.m 10451 2015-06-10 22:00:07Z roboos $
% if nargin<2, keepsourcedimord = 0; end
%
@@ -147,7 +147,7 @@
case {'voxel' 'vox' 'repl' 'wcond'}
% these are used in some fieldtrip functions, but are not considered standard
- warning_once('unexpected dimord "%s"', data.dimord);
+ ft_warning('unexpected dimord "%s"', data.dimord);
case {'pos'}
% this is for source data on a 3-d grid, a cortical sheet, or unstructured positions
diff --git a/external/fieldtrip/utilities/private/fixname.m b/external/fieldtrip/utilities/private/fixname.m
index b93dd7d1..8e3d4133 100644
--- a/external/fieldtrip/utilities/private/fixname.m
+++ b/external/fieldtrip/utilities/private/fixname.m
@@ -8,7 +8,7 @@
% str = fixname(str)
%
%
-% MATLAB 2014a introduces the matlab.lang.makeValidName and
+% MATLAB 2014a introduces the matlab.lang.makeValidName and
% matlab.lang.makeUniqueStrings functions for constructing unique MATLAB identifiers,
% but this particular implementation also works with older MATLAB versions.
%
@@ -32,7 +32,7 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: fixname.m 9795 2014-09-11 13:02:30Z jansch $
+% $Id: fixname.m 10455 2015-06-11 21:30:27Z roboos $
str = lower(str);
str(regexp(str,'\W')) = '_';
@@ -40,8 +40,14 @@
while(str(1) == '_'), str = str(2:end); end; % remove all underscore at the begin of the string
while(str(end) == '_'), str = str(1:end-1); end; % remove all underscore at the end of the string
-%if ~isempty(str2double(str(1))) && ~isequal(str(1), 'i')
if int8(str(1))<58 && int8(str(1))>47
% the string begins with a digit, prepend an 'x'
str = ['x' str];
end
+
+% truncate the string if it's too long: MATLAB maximizes the string length to 63
+% characters (and throws a warning when truncating)
+if numel(str)>63
+ ft_warning(sprintf('%s exceeds MATLAB''s maximum name length of 63 characters and has been truncated to %s',str,str(1:63)));
+ str = str(1:63);
+end
diff --git a/external/fieldtrip/utilities/private/fixpos.m b/external/fieldtrip/utilities/private/fixpos.m
index 7028f01f..3288c66c 100644
--- a/external/fieldtrip/utilities/private/fixpos.m
+++ b/external/fieldtrip/utilities/private/fixpos.m
@@ -6,16 +6,24 @@
recurse = 1;
end
+if ~isa(data, 'struct')
+ return;
+end
+
if numel(data)>1
% loop over all individual elements
+ clear tmp
for i=1:numel(data)
- data(i) = fixpos(data(i));
+ % this is to prevent an "Subscripted assignment between dissimilar structures" error
+ tmp(i) = fixpos(data(i));
end
+ data = tmp;
+ clear tmp
return
end
% replace pnt by pos
-if isfield(data, 'pnt') && ~isfield(data, 'label')
+if isfield(data, 'pnt')
data.pos = data.pnt;
data = rmfield(data, 'pnt');
end
diff --git a/external/fieldtrip/utilities/private/fixsampleinfo.m b/external/fieldtrip/utilities/private/fixsampleinfo.m
index 5fe58600..d82ec5f6 100644
--- a/external/fieldtrip/utilities/private/fixsampleinfo.m
+++ b/external/fieldtrip/utilities/private/fixsampleinfo.m
@@ -63,20 +63,20 @@
end
if isempty(trl)
- warning_once('the data does not contain a trial definition');
+ ft_warning('the data does not contain a trial definition');
elseif ~isempty(trl) && size(trl,1)~=numel(nsmp)
- warning_once('the trial definition in the configuration is inconsistent with the actual data');
+ ft_warning('the trial definition in the configuration is inconsistent with the actual data');
trl = [];
elseif size(trl,1)~=ntrial
- warning_once('the trial definition in the configuration is inconsistent with the actual data');
+ ft_warning('the trial definition in the configuration is inconsistent with the actual data');
trl = [];
elseif nsmp~=(trl(:,2)-trl(:,1)+1)
- warning_once('the trial definition in the configuration is inconsistent with the actual data');
+ ft_warning('the trial definition in the configuration is inconsistent with the actual data');
trl = [];
end
if isempty(trl) || ~all(nsmp==trl(:,2)-trl(:,1)+1)
- warning_once('reconstructing sampleinfo by assuming that the trials are consecutive segments of a continuous recording');
+ ft_warning('reconstructing sampleinfo by assuming that the trials are consecutive segments of a continuous recording');
% construct a trial definition on the fly, assume that the trials are
% consecutive segments of a continuous recording
if ntrial==1,
@@ -103,7 +103,7 @@
data.sampleinfo = trl(:, 1:2);
elseif ~isfield(data, 'sampleinfo') && isempty(trl)
% this is probably an unreachable statement
- warning_once('failed to create sampleinfo field');
+ ft_warning('failed to create sampleinfo field');
end
if (~isfield(data, 'trialinfo') || isempty(data.trialinfo)) && ~isempty(trl) && size(trl, 2) > 3,
diff --git a/external/fieldtrip/utilities/private/ft_findcfg.m b/external/fieldtrip/utilities/private/ft_findcfg.m
index 18ebda5a..56405e79 100644
--- a/external/fieldtrip/utilities/private/ft_findcfg.m
+++ b/external/fieldtrip/utilities/private/ft_findcfg.m
@@ -4,12 +4,14 @@
% or in the nested previous cfgs
%
% Use as
-% [val] = ft_findcfg(cfg, var)
+% val = ft_findcfg(cfg, var)
% where the name of the variable should be specified as string.
%
% e.g.
% trl = ft_findcfg(cfg, 'trl')
% event = ft_findcfg(cfg, 'event')
+%
+% See also FT_GETOPT, FT_CFG2KEYVAL
% Copyright (C) 2006, Robert Oostenveld
%
@@ -29,7 +31,7 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: ft_findcfg.m 9792 2014-09-11 09:50:15Z jansch $
+% $Id: ft_findcfg.m 11053 2016-01-09 17:51:21Z roboos $
% if var(1)~='.'
% var = ['.' var];
@@ -61,4 +63,3 @@
break
end
end
-
diff --git a/external/fieldtrip/utilities/private/ft_platform_supports.m b/external/fieldtrip/utilities/private/ft_platform_supports.m
new file mode 100644
index 00000000..a160fa7d
--- /dev/null
+++ b/external/fieldtrip/utilities/private/ft_platform_supports.m
@@ -0,0 +1,244 @@
+function tf = ft_platform_supports(what,varargin)
+
+% FT_PLATFORM_SUPPORTS returns a boolean indicating whether the current platform
+% supports a specific capability
+%
+% Usage:
+% tf = ft_platform_supports(what)
+% tf = ft_platform_supports('matlabversion', min_version, max_version)
+%
+% The following values are allowed for the 'what' parameter:
+% value means that the following is supported:
+%
+% 'which-all' which(...,'all')
+% 'exists-in-private-directory' exists(...) will look in the /private
+% subdirectory to see if a file exists
+% 'onCleanup' onCleanup(...)
+% 'int32_logical_operations' bitand(a,b) with a, b of type int32
+% 'graphics_objects' graphics sysem is object-oriented
+% 'libmx_c_interface' libmx is supported through mex in the
+% C-language (recent Matlab versions only
+% support C++)
+% 'program_invocation_name' program_invocation_name() (GNU Octave)
+% 'singleCompThread' start Matlab with -singleCompThread
+% 'nosplash' -nosplash
+% 'nodisplay' -nodisplay
+% 'nojvm' -nojvm
+% 'no-gui' start GNU Octave with --no-gui
+% 'RandStream.setGlobalStream' RandStream.setGlobalStream(...)
+% 'RandStream.setDefaultStream' RandStream.setDefaultStream(...)
+% 'rng' rng(...)
+% 'rand-state' rand('state')
+% 'urlread-timeout' urlread(..., 'Timeout', t)
+
+if ~ischar(what)
+ error('first argument must be a string');
+end
+
+switch what
+ case 'matlabversion'
+ tf = is_matlab() && matlabversion(varargin{:});
+
+ case 'exists-in-private-directory'
+ tf = is_matlab();
+
+ case 'which-all'
+ tf = is_matlab();
+
+ case 'onCleanup'
+ tf = is_octave() || matlabversion(7.8, Inf);
+
+ case 'int32_logical_operations'
+ % earlier version of Matlab don't support bitand (and similar)
+ % operations on int32
+ tf = is_octave() || ~matlabversion(-inf, '2012a');
+
+ case 'graphics_objects'
+ % introduced in Matlab 2014b, graphics is handled through objects;
+ % previous versions use numeric handles
+ tf = is_matlab() && matlabversion('2014b', Inf);
+
+ case 'libmx_c_interface'
+ % removed after 2013b
+ tf = matlabversion(-Inf, '2013b');
+
+ case 'program_invocation_name'
+ % Octave supports program_invocation_name, which returns the path
+ % of the binary that was run to start Octave
+ tf = is_octave();
+
+ case 'singleCompThread'
+ tf = is_matlab() && matlabversion(7.8, inf);
+
+ case {'nosplash','nodisplay','nojvm'}
+ % Only on Matlab
+ tf = is_matlab();
+
+ case 'no-gui'
+ % Only on Octave
+ tf = is_octave();
+
+ case 'RandStream.setDefaultStream'
+ tf = is_matlab() && matlabversion('2008b', '2011b');
+
+ case 'RandStream.setGlobalStream'
+ tf = is_matlab() && matlabversion('2012a', inf);
+
+ case 'randomized_PRNG_on_startup'
+ tf = is_octave() || ~matlabversion(-Inf,'7.3');
+
+ case 'rng'
+ % recent Matlab versions
+ tf = is_matlab() && matlabversion('7.12',Inf);
+
+ case 'rand-state'
+ % GNU Octave
+ tf = is_octave();
+
+ case 'urlread-timeout'
+ tf = matlabversion('2012b',Inf);
+
+ otherwise
+ error('unsupported value for first argument: %s', what);
+
+end % switch
+
+end % function
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% SUBFUNCTION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function tf = is_matlab()
+tf = ~is_octave();
+end % function
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% SUBFUNCTION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function tf = is_octave()
+persistent cached_tf;
+
+if isempty(cached_tf)
+ cached_tf = logical(exist('OCTAVE_VERSION', 'builtin'));
+end
+
+tf = cached_tf;
+end % function
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% SUBFUNCTION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function [inInterval] = matlabversion(min, max)
+
+% MATLABVERSION checks if the current MATLAB version is within the interval
+% specified by min and max.
+%
+% Use, e.g., as:
+% if matlabversion(7.0, 7.9)
+% % do something
+% end
+%
+% Both strings and numbers, as well as infinities, are supported, eg.:
+% matlabversion(7.1, 7.9) % is version between 7.1 and 7.9?
+% matlabversion(6, '7.10') % is version between 6 and 7.10? (note: '7.10', not 7.10)
+% matlabversion(-Inf, 7.6) % is version <= 7.6?
+% matlabversion('2009b') % exactly 2009b
+% matlabversion('2008b', '2010a') % between two versions
+% matlabversion('2008b', Inf) % from a version onwards
+% etc.
+%
+% See also VERSION, VER, VERLESSTHAN
+
+% Copyright (C) 2006, Robert Oostenveld
+% Copyright (C) 2010, Eelke Spaak
+%
+% This file is part of FieldTrip, see http://www.ru.nl/neuroimaging/fieldtrip
+% for the documentation and details.
+%
+% FieldTrip is free software: you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation, either version 3 of the License, or
+% (at your option) any later version.
+%
+% FieldTrip is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU General Public License
+% along with FieldTrip. If not, see .
+%
+% $Id: ft_platform_supports.m 10466 2015-06-22 16:39:29Z roboos $
+
+% this does not change over subsequent calls, making it persistent speeds it up
+persistent curVer
+
+if nargin<2
+ max = min;
+end
+
+if isempty(curVer)
+ curVer = version();
+end
+
+if ((ischar(min) && isempty(str2num(min))) || (ischar(max) && isempty(str2num(max))))
+ % perform comparison with respect to release string
+
+ ind = strfind(curVer, '(R');
+ [year, ab] = parseMatlabRelease(curVer((ind + 2):(numel(curVer) - 1)));
+
+ [minY, minAb] = parseMatlabRelease(min);
+ [maxY, maxAb] = parseMatlabRelease(max);
+
+ inInterval = orderedComparison(minY, minAb, maxY, maxAb, year, ab);
+else % perform comparison with respect to version number
+ [major, minor] = parseMatlabVersion(curVer);
+ [minMajor, minMinor] = parseMatlabVersion(min);
+ [maxMajor, maxMinor] = parseMatlabVersion(max);
+
+ inInterval = orderedComparison(minMajor, minMinor, maxMajor, maxMinor, major, minor);
+end
+
+ function [year, ab] = parseMatlabRelease(str)
+ if (str == Inf)
+ year = Inf; ab = Inf;
+ elseif (str == -Inf)
+ year = -Inf; ab = -Inf;
+ else
+ year = str2num(str(1:4));
+ ab = str(5);
+ end
+ end
+
+ function [major, minor] = parseMatlabVersion(ver)
+ if (ver == Inf)
+ major = Inf; minor = Inf;
+ elseif (ver == -Inf)
+ major = -Inf; minor = -Inf;
+ elseif (isnumeric(ver))
+ major = floor(ver);
+ minor = int8((ver - floor(ver)) * 10);
+ else % ver is string (e.g. '7.10'), parse accordingly
+ [major, rest] = strtok(ver, '.');
+ major = str2num(major);
+ minor = str2num(strtok(rest, '.'));
+ end
+ end
+
+% checks if testA is in interval (lowerA,upperA); if at edges, checks if testB is in interval (lowerB,upperB).
+ function inInterval = orderedComparison(lowerA, lowerB, upperA, upperB, testA, testB)
+ if (testA < lowerA || testA > upperA)
+ inInterval = false;
+ else
+ inInterval = true;
+ if (testA == lowerA)
+ inInterval = inInterval && (testB >= lowerB);
+ end
+
+ if (testA == upperA)
+ inInterval = inInterval && (testB <= upperB);
+ end
+ end
+ end
+
+end % function
diff --git a/external/fieldtrip/utilities/private/ft_postamble_debug.m b/external/fieldtrip/utilities/private/ft_postamble_debug.m
index 97895150..68a98fe6 100644
--- a/external/fieldtrip/utilities/private/ft_postamble_debug.m
+++ b/external/fieldtrip/utilities/private/ft_postamble_debug.m
@@ -23,8 +23,19 @@
% these are still needed by the cleanup function
otherwise
- % this results in the cleanup function doing nothing
- Ce9dei2ZOo_debug = 'no';
- Ce9dei2ZOo_funname = [];
- Ce9dei2ZOo_argin = [];
+ % stack(1) is this script
+ % stack(2) is the calling ft_postamble function
+ % stack(3) is the main FieldTrip function that we are interested in
+ Ce9dei2ZOx_funname = dbstack;
+ Ce9dei2ZOx_funname = Ce9dei2ZOx_funname(3).name;
+
+ if isequal(Ce9dei2ZOx_funname, Ce9dei2ZOo_funname)
+ % this results in the cleanup function doing nothing
+ Ce9dei2ZOo_debug = 'no';
+ Ce9dei2ZOo_funname = [];
+ Ce9dei2ZOo_argin = [];
+ else
+ % this happens for nested fieldtrip functions, e.g. when
+ % ft_selectdata is called by another high-level function
+ end
end
diff --git a/external/fieldtrip/utilities/private/ft_postamble_history.m b/external/fieldtrip/utilities/private/ft_postamble_history.m
index 24d3ded9..92be173b 100644
--- a/external/fieldtrip/utilities/private/ft_postamble_history.m
+++ b/external/fieldtrip/utilities/private/ft_postamble_history.m
@@ -25,7 +25,7 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: ft_postamble_history.m 9561 2014-05-21 06:50:39Z roboos $
+% $Id: ft_postamble_history.m 10451 2015-06-10 22:00:07Z roboos $
global ft_default
@@ -56,4 +56,4 @@
clear tmpindx
% clear warnings from ft_default, so that they don't end up in the next cfg
-warning_once('-clear');
+ft_warning('-clear');
diff --git a/external/fieldtrip/utilities/private/ft_preamble_init.m b/external/fieldtrip/utilities/private/ft_preamble_init.m
index 633dd931..bac4b0a3 100644
--- a/external/fieldtrip/utilities/private/ft_preamble_init.m
+++ b/external/fieldtrip/utilities/private/ft_preamble_init.m
@@ -1,10 +1,12 @@
-% FT_PREAMBLE_INIT is a helper script that display the calling-function's
-% help in case the user did not specify any input argument. This can be
-% used in all fieldtrip main functions that take at least a cfg input
-% argument, and most also take one or multiple data structures.
+% FT_PREAMBLE_INIT is a helper script that is used at the start of all FieldTrip main
+% functions. It checks whether the user specified at lease one input arguments (i.e.
+% the cfg) or shows the help of the calling function. It checks whether the output file
+% already exists and whether it is OK to overwrite it. It tracks the function call.
%
% Use as
% ft_preamble init
+%
+% See also FT_TRACKUSAGE
% Copyright (C) 2011-2012, Robert Oostenveld, DCCN
%
@@ -24,7 +26,10 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: ft_preamble_init.m 9561 2014-05-21 06:50:39Z roboos $
+% $Id: ft_preamble_init.m 10896 2015-11-17 12:31:35Z roboos $
+
+% disabled for now, see further down
+global ft_default
if nargin==0
stack = dbstack('-completenames');
@@ -38,12 +43,25 @@
msg.identifier = '';
msg.stack = stack;
error(msg);
-end
+end % if nargin
+
+% this script requires some options that can be user-specified, but otherwise are obtained from ft_default
+% merge the default options into the configuration, except the preamble field which is used for passing arguments
+cfg = mergeconfig(cfg, rmfield(ft_default, 'preamble'));
% determine whether function execution should be aborted or continued
-if isfield(cfg, 'outputfile') && ~isempty(cfg.outputfile) && isfield(cfg, 'outputfilepresent') && ~isempty(cfg.outputfilepresent)
+if isfield(cfg, 'outputfile') && ~isempty(cfg.outputfile)
+ assert(any(strcmp(fieldnames(cfg), 'outputfilepresent')), 'cfg.outputfilepresent is a required option, please see FT_DEFAULTS');
% check whether the output file already exists
- if ~exist(cfg.outputfile, 'file')
+ [p, f, x] = fileparts(cfg.outputfile);
+ if isempty(p)
+ % the relative path was speciield
+ outputfile = fullfile(pwd, cfg.outputfile);
+ else
+ % the absolute path was specified
+ outputfile = cfg.outputfile;
+ end
+ if ~exist(outputfile, 'file')
abort = false;
else
% the output file exists, determine how to deal with it
@@ -58,16 +76,28 @@
warning('output file %s is already present: aborting function execution', cfg.outputfile);
abort = true;
end
- case 'error'
- error('output file %s is already present', cfg.outputfile);
case 'overwrite'
warning('output file %s is already present: it will be overwritten', cfg.outputfile);
abort = false;
+ case 'error'
+ error('output file %s is already present', cfg.outputfile);
otherwise
error('invalid option for cfg.outputfilepresent');
end % case
end
else
+ % there is no reason to abort execution
abort = false;
-end
+end % if outputfile
+if false
+ % this is currently generating too much data and therefore disabled
+ if isfield(ft_default, 'trackusage') && ~(isequal(ft_default.trackusage, false) || isequal(ft_default.trackusage, 'no') || isequal(ft_default.trackusage, 'off'))
+ % track the usage of the calling function
+ stack = dbstack('-completenames');
+ % stack(1) is this script
+ % stack(2) is the calling ft_postamble function
+ % stack(3) is the main FieldTrip function that we are interested in
+ ft_trackusage('function call', 'function', stack(3).name);
+ end % if trackusage
+end
diff --git a/external/fieldtrip/utilities/private/ft_preamble_provenance.m b/external/fieldtrip/utilities/private/ft_preamble_provenance.m
index c9355a67..692da49d 100644
--- a/external/fieldtrip/utilities/private/ft_preamble_provenance.m
+++ b/external/fieldtrip/utilities/private/ft_preamble_provenance.m
@@ -34,7 +34,7 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: ft_preamble_provenance.m 9900 2014-10-13 15:06:43Z roboos $
+% $Id: ft_preamble_provenance.m 10765 2015-10-09 18:10:47Z roboos $
% Record the start time and memory. These are used by ft_postamble_callinfo, which
% stores them in the output cfg.callinfo. In the mean time, they are stored in the
@@ -58,7 +58,11 @@
if isequal(ft_default.preamble, {'varargin'})
tmpargin = varargin;
else
- tmpargin = cellfun(@eval, ft_default.preamble, 'UniformOutput', false);
+ isvar = cellfun(@(x) exist(x, 'var')==1, ft_default.preamble);
+ tmpargin = cellfun(@eval, ft_default.preamble(isvar), 'UniformOutput', false);
+ tmpargin( isvar) = tmpargin;
+ tmpargin(~isvar) = {[]};
+ clear isvar
end
cfg.callinfo.inputhash = cell(1,numel(tmpargin));
for iargin = 1:numel(tmpargin)
diff --git a/external/fieldtrip/utilities/private/ft_preamble_trackconfig.m b/external/fieldtrip/utilities/private/ft_preamble_trackconfig.m
index d83462b0..6b1df648 100644
--- a/external/fieldtrip/utilities/private/ft_preamble_trackconfig.m
+++ b/external/fieldtrip/utilities/private/ft_preamble_trackconfig.m
@@ -27,15 +27,11 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: ft_preamble_trackconfig.m 9561 2014-05-21 06:50:39Z roboos $
+% $Id: ft_preamble_trackconfig.m 10896 2015-11-17 12:31:35Z roboos $
% otherwise the empty field would end up in the output cfg
global ft_default
-ft_default = rmfield(ft_default, 'preamble');
% most fieldtrip functions should allow for configuration tracking, except for
% the functions that take a cfg as input and return a cfg as output
cfg = ft_checkconfig(cfg, 'trackconfig', 'on');
-
-% the calling ft_preable expects it to be present
-ft_default.preamble = {};
diff --git a/external/fieldtrip/external/stats/randsample.m b/external/fieldtrip/utilities/private/getaddress.m
similarity index 50%
rename from external/fieldtrip/external/stats/randsample.m
rename to external/fieldtrip/utilities/private/getaddress.m
index 055ece31..8b342669 100644
--- a/external/fieldtrip/external/stats/randsample.m
+++ b/external/fieldtrip/utilities/private/getaddress.m
@@ -1,18 +1,15 @@
-function [y] = randsample(x, k)
+function address = getip(hostname)
-% RANDSAMPLE Random sample, with or without replacement. This is a drop-in
-% replacement for the matlab funnction with the same name. Not all options
-% are supported, an error will be issued if needed.
+% GETADDRESS returns the IP address
%
-% Y = RANDSAMPLE(N,K) returns Y as a 1-by-K vector of values sampled
-% uniformly at random, without replacement, from the integers 1:N.
+% Use as
+% address = getaddress();
+% or
+% address = getaddress(hostname);
%
-% Y = RANDSAMPLE(POPULATION,K) returns K values sampled uniformly at
-% random, without replacement, from the values in the vector POPULATION.
-%
-% See also RAND, RANDPERM.
+% See also GETUSERNAME, GETHOSTNAME
-% Copyright (C) 2007, Robert Oostenveld
+% Copyright (C) 2015, Robert Oostenveld
%
% This file is part of FieldTrip, see http://www.ru.nl/neuroimaging/fieldtrip
% for the documentation and details.
@@ -30,15 +27,27 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: randsample.m 8410 2013-08-21 14:16:44Z eelspa $
+% $Id: getaddress.m 10452 2015-06-11 02:14:45Z roboos $
+
+% this is to speed up subsequent calls
+persistent previous_argin previous_argout
+
+if nargin==0
+ hostname = [];
+end
-if nargin>2
- error('only two input variables are supported');
+if ~isempty(previous_argout) && isequal(hostname, previous_argin)
+ address = previous_argout;
+ return
end
-if length(x)==1 && isnumeric(x)
- x = 1:x;
+if ~isempty(hostname)
+ address = java.net.InetAddress.getByName(hostname);
+else
+ address = java.net.InetAddress.getLocalHost;
end
+address = char(address.getHostAddress);
-sel = ceil(rand(1,k)*length(x));
-y = x(sel);
+% remember for subsequent calls
+previous_argin = hostname;
+previous_argout = address;
diff --git a/external/fieldtrip/utilities/private/getdatfield.m b/external/fieldtrip/utilities/private/getdatfield.m
new file mode 100644
index 00000000..6849eee2
--- /dev/null
+++ b/external/fieldtrip/utilities/private/getdatfield.m
@@ -0,0 +1,32 @@
+function [datfield, dimord] = getdatfield(data)
+
+% GETDATFIELD
+%
+% Use as
+% [datfield, dimord] = getdatfield(data)
+% where the output arguments are cell-arrays.
+%
+% See also GETDIMORD, GETDIMSIZ
+
+datfield = fieldnames(data);
+
+% these descriptive fields are cell-arrays and not treated as data
+% the descriptive fields such as time and freq can be treated as data
+xtrafield = {'label' 'labelcmb'};
+datfield = setdiff(datfield, xtrafield);
+
+xtrafield = {'cfg' 'hdr' 'fsample' 'fsampleorig' 'grad' 'elec' 'opto' 'transform' 'dim' 'unit' 'coordsys' 'tri' 'tet' 'hex'};
+datfield = setdiff(datfield, xtrafield);
+
+orgdim1 = datfield(~cellfun(@isempty, regexp(datfield, 'label$'))); % xxxlabel
+datfield = setdiff(datfield, orgdim1);
+datfield = datfield(:)';
+
+orgdim1 = datfield(~cellfun(@isempty, regexp(datfield, 'dimord$'))); % xxxdimord
+datfield = setdiff(datfield, orgdim1);
+datfield = datfield(:)';
+
+dimord = cell(size(datfield));
+for i=1:length(datfield)
+ dimord{i} = getdimord(data, datfield{i});
+end
diff --git a/external/fieldtrip/utilities/private/getdimord.m b/external/fieldtrip/utilities/private/getdimord.m
index 43fd23f9..e26bdc25 100644
--- a/external/fieldtrip/utilities/private/getdimord.m
+++ b/external/fieldtrip/utilities/private/getdimord.m
@@ -5,7 +5,7 @@
% Use as
% dimord = getdimord(data, field)
%
-% See also GETDIMSIZ
+% See also GETDIMSIZ, GETDATFIELD
if ~isfield(data, field) && isfield(data, 'avg') && isfield(data.avg, field)
field = ['avg.' field];
@@ -57,6 +57,9 @@
ntopochan = inf;
nspike = inf; % this is only for the first spike channel
nlag = nan;
+ndim1 = nan;
+ndim2 = nan;
+ndim3 = nan;
% use an anonymous function
assign = @(var, val) assignin('caller', var, val);
@@ -119,6 +122,12 @@
npos = prod(data.dim);
end
+if isfield(data, 'dim')
+ ndim1 = data.dim(1);
+ ndim2 = data.dim(2);
+ ndim3 = data.dim(3);
+end
+
if isfield(data, 'csdlabel')
% this is used in PCC beamformers
if length(data.csdlabel)==npos
@@ -154,8 +163,8 @@
% determine the size of the actual data
datsiz = getdimsiz(data, field);
-tok = {'subj' 'rpt' 'rpttap' 'chan' 'chancmb' 'freq' 'time' 'pos' 'ori' 'topochan' 'lag'};
-siz = [nsubj nrpt nrpttap nchan nchancmb nfreq ntime npos nori ntopochan nlag];
+tok = {'subj' 'rpt' 'rpttap' 'chan' 'chancmb' 'freq' 'time' 'pos' 'ori' 'topochan' 'lag' 'dim1' 'dim2' 'dim3'};
+siz = [nsubj nrpt nrpttap nchan nchancmb nfreq ntime npos nori ntopochan nlag ndim1 ndim2 ndim3];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ATTEMPT 2: a general dimord is present and might apply
@@ -200,6 +209,11 @@
% note that the case for a cell dimension (typically pos) is handled at
% the end of this section
+ case {'pos'}
+ if isequalwithoutnans(datsiz, [npos 3])
+ dimord = 'pos_unknown';
+ end
+
case {'individual'}
if isequalwithoutnans(datsiz, [nsubj nchan ntime])
dimord = 'subj_chan_time';
@@ -417,7 +431,7 @@
dimord = '{chan}_spike';
elseif ft_datatype(data, 'raw') && iscell(data.(field)) && datsiz(1)==nrpt
dimord = '{rpt}_time';
- elseif isvector(data.(field)) && isequal(datsiz, [1 ntime])
+ elseif isvector(data.(field)) && isequal(datsiz, [1 ntime ones(1,numel(datsiz)-2)])
dimord = 'time';
end
@@ -428,8 +442,7 @@
otherwise
if isfield(data, 'dim') && isequal(datsiz, data.dim)
- % FIXME is this the desired dimord for volume data? A dimord of vox or voxel is not recommended according to fixdimord.
- dimord = 'pos';
+ dimord = 'dim1_dim2_dim3';
end
end % switch field
@@ -485,6 +498,9 @@
dimtok(datsiz==nchan) = {'chan'};
dimtok(datsiz==nfreq) = {'freq'};
dimtok(datsiz==ntime) = {'time'};
+ dimtok(datsiz==ndim1) = {'dim1'};
+ dimtok(datsiz==ndim2) = {'dim2'};
+ dimtok(datsiz==ndim3) = {'dim3'};
if isempty(dimtok{end}) && datsiz(end)==1
% remove the unknown trailing singleton dimension
@@ -505,8 +521,17 @@
end
end % if dimord does not exist
+if ~exist('dimord', 'var')
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ % ATTEMPT 6: check whether it is a 3-D volume
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ if isequal(datsiz, [ndim1 ndim2 ndim3])
+ dimord = 'dim1_dim2_dim3';
+ end
+end % if dimord does not exist
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% ATTEMPT 6: return "unknown" for all unknown dimensions
+% FINAL RESORT: return "unknown" for all unknown dimensions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if ~exist('dimord', 'var')
% this should not happen
diff --git a/external/fieldtrip/utilities/private/getdimsiz.m b/external/fieldtrip/utilities/private/getdimsiz.m
index 16582648..90e27771 100644
--- a/external/fieldtrip/utilities/private/getdimsiz.m
+++ b/external/fieldtrip/utilities/private/getdimsiz.m
@@ -5,7 +5,17 @@
% Use as
% dimsiz = getdimsiz(data, field)
%
-% See also GETDIMORD
+% If the length of the vector that is returned is smaller than the
+% number of dimensions that you would expect from GETDIMORD, you
+% should assume that it has trailing singleton dimensions.
+%
+% Example use
+% dimord = getdimord(datastructure, fieldname);
+% dimtok = tokenize(dimord, '_');
+% dimsiz = getdimsiz(datastructure, fieldname);
+% dimsiz(end+1:length(dimtok)) = 1; % there can be additional trailing singleton dimensions
+%
+% See also GETDIMORD, GETDATFIELD
if ~isfield(data, field) && isfield(data, 'avg') && isfield(data.avg, field)
field = ['avg.' field];
@@ -42,7 +52,15 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function siz = cellmatsize(x)
if iscell(x)
- cellsize = numel(x); % the number of elements in the cell-array
+ if isempty(x)
+ siz = 0;
+ return % nothing else to do
+ elseif isvector(x)
+ cellsize = numel(x); % the number of elements in the cell-array
+ else
+ cellsize = size(x);
+ x = x(:); % convert to vector for further size detection
+ end
[dum, indx] = max(cellfun(@numel, x));
matsize = size(x{indx}); % the size of the content of the cell-array
siz = [cellsize matsize]; % concatenate the two
diff --git a/external/fieldtrip/utilities/private/gethostname.m b/external/fieldtrip/utilities/private/gethostname.m
index d62bfc35..89539ac0 100644
--- a/external/fieldtrip/utilities/private/gethostname.m
+++ b/external/fieldtrip/utilities/private/gethostname.m
@@ -1,9 +1,11 @@
function host = gethostname()
-% HOSTNAME
+% HOSTNAME returns the hostname of this computer
%
% Use as
% str = hostname;
+%
+% See also GETUSERNAME, GETADDRESS
% Copyright (C) 2011, Eelke Spaak
%
@@ -23,7 +25,7 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: gethostname.m 8776 2013-11-14 09:04:48Z roboos $
+% $Id: gethostname.m 10452 2015-06-11 02:14:45Z roboos $
% this is to speed up subsequent calls
persistent previous_argout
diff --git a/external/fieldtrip/utilities/private/getusername.m b/external/fieldtrip/utilities/private/getusername.m
index bc7a6205..5d1ef945 100644
--- a/external/fieldtrip/utilities/private/getusername.m
+++ b/external/fieldtrip/utilities/private/getusername.m
@@ -3,7 +3,7 @@
% GETUSERNAME
%
% Use as
-% str = username;
+% str = getusername();
% Copyright (C) 2011-2012, Robert Oostenveld
%
@@ -23,7 +23,7 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: getusername.m 7123 2012-12-06 21:21:38Z roboos $
+% $Id: getusername.m 10453 2015-06-11 02:14:49Z roboos $
% this is to speed up subsequent calls
persistent previous_argout
diff --git a/external/fieldtrip/utilities/private/icosahedron.m b/external/fieldtrip/utilities/private/icosahedron.m
index 92d14ed8..06560f93 100644
--- a/external/fieldtrip/utilities/private/icosahedron.m
+++ b/external/fieldtrip/utilities/private/icosahedron.m
@@ -1,8 +1,8 @@
-function [pnt, tri] = icosahedron()
+function [pos, tri] = icosahedron()
% ICOSAHEDRON creates an icosahedron
%
-% [pnt, tri] = icosahedron
+% [pos, tri] = icosahedron
% creates an icosahedron with 12 vertices and 20 triangles
%
% See also OCTAHEDRON, ICOSAHEDRON42, ICOSAHEDRON162, ICOSAHEDRON642, ICOSAHEDRON2562
@@ -25,7 +25,7 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: icosahedron.m 9664 2014-06-22 07:06:29Z roboos $
+% $Id: icosahedron.m 10772 2015-10-14 07:36:57Z roboos $
tri = [
1 2 3
@@ -50,20 +50,20 @@
12 7 11
];
-pnt = zeros(12, 3);
+pos = zeros(12, 3);
rho=0.4*sqrt(5);
phi=2*pi*(0:4)/5;
-pnt( 1, :) = [0 0 1]; % top point
+pos( 1, :) = [0 0 1]; % top point
-pnt(2:6, 1) = rho*cos(phi)';
-pnt(2:6, 2) = rho*sin(phi)';
-pnt(2:6, 3) = rho/2;
+pos(2:6, 1) = rho*cos(phi)';
+pos(2:6, 2) = rho*sin(phi)';
+pos(2:6, 3) = rho/2;
-pnt(7:11, 1) = rho*cos(phi - pi/5)';
-pnt(7:11, 2) = rho*sin(phi - pi/5)';
-pnt(7:11, 3) = -rho/2;
+pos(7:11, 1) = rho*cos(phi - pi/5)';
+pos(7:11, 2) = rho*sin(phi - pi/5)';
+pos(7:11, 3) = -rho/2;
-pnt(12, :) = [0 0 -1]; % bottom point
+pos(12, :) = [0 0 -1]; % bottom point
diff --git a/external/fieldtrip/utilities/private/icosahedron42.m b/external/fieldtrip/utilities/private/icosahedron42.m
index 5aa47e52..5a848482 100644
--- a/external/fieldtrip/utilities/private/icosahedron42.m
+++ b/external/fieldtrip/utilities/private/icosahedron42.m
@@ -1,4 +1,4 @@
-function [pnt, tri] = icosahedron42()
+function [pos, tri] = icosahedron42()
% ICOSAHEDRON42 creates a 1-fold refined icosahedron
@@ -20,9 +20,9 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: icosahedron42.m 9664 2014-06-22 07:06:29Z roboos $
+% $Id: icosahedron42.m 10772 2015-10-14 07:36:57Z roboos $
-[pnt, tri] = icosahedron;
-[pnt, tri] = refine(pnt, tri);
+[pos, tri] = icosahedron;
+[pos, tri] = refine(pos, tri);
-pnt = pnt ./ repmat(sqrt(sum(pnt.^2,2)), 1,3);
+pos = pos ./ repmat(sqrt(sum(pos.^2,2)), 1,3);
diff --git a/external/fieldtrip/utilities/private/lmoutr.mexw32 b/external/fieldtrip/utilities/private/lmoutr.mexw32
index f4d88620..7be79de1 100755
Binary files a/external/fieldtrip/utilities/private/lmoutr.mexw32 and b/external/fieldtrip/utilities/private/lmoutr.mexw32 differ
diff --git a/external/fieldtrip/utilities/private/lmoutr.mexw64 b/external/fieldtrip/utilities/private/lmoutr.mexw64
index 62e72e7c..8ad4f571 100755
Binary files a/external/fieldtrip/utilities/private/lmoutr.mexw64 and b/external/fieldtrip/utilities/private/lmoutr.mexw64 differ
diff --git a/external/fieldtrip/utilities/private/matlabversion.m b/external/fieldtrip/utilities/private/matlabversion.m
deleted file mode 100644
index 87593b91..00000000
--- a/external/fieldtrip/utilities/private/matlabversion.m
+++ /dev/null
@@ -1,114 +0,0 @@
-function [inInterval] = matlabversion(min, max)
-
-% MATLABVERSION checks if the current MATLAB version is within the interval
-% specified by min and max.
-%
-% Use, e.g., as:
-% if matlabversion(7.0, 7.9)
-% % do something
-% end
-%
-% Both strings and numbers, as well as infinities, are supported, eg.:
-% matlabversion(7.1, 7.9) % is version between 7.1 and 7.9?
-% matlabversion(6, '7.10') % is version between 6 and 7.10? (note: '7.10', not 7.10)
-% matlabversion(-Inf, 7.6) % is version <= 7.6?
-% matlabversion('2009b') % exactly 2009b
-% matlabversion('2008b', '2010a') % between two versions
-% matlabversion('2008b', Inf) % from a version onwards
-% etc.
-%
-% See also VERSION, VER, VERLESSTHAN
-
-% Copyright (C) 2006, Robert Oostenveld
-% Copyright (C) 2010, Eelke Spaak
-%
-% This file is part of FieldTrip, see http://www.ru.nl/neuroimaging/fieldtrip
-% for the documentation and details.
-%
-% FieldTrip is free software: you can redistribute it and/or modify
-% it under the terms of the GNU General Public License as published by
-% the Free Software Foundation, either version 3 of the License, or
-% (at your option) any later version.
-%
-% FieldTrip is distributed in the hope that it will be useful,
-% but WITHOUT ANY WARRANTY; without even the implied warranty of
-% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-% GNU General Public License for more details.
-%
-% You should have received a copy of the GNU General Public License
-% along with FieldTrip. If not, see .
-%
-% $Id: matlabversion.m 10198 2015-02-11 09:36:13Z roboos $
-
-% this does not change over subsequent calls, making it persistent speeds it up
-persistent curVer
-
-if nargin<2
- max = min;
-end
-
-if isempty(curVer)
- curVer = version();
-end
-
-if ((ischar(min) && isempty(str2num(min))) || (ischar(max) && isempty(str2num(max))))
- % perform comparison with respect to release string
-
- ind = strfind(curVer, '(R');
- [year, ab] = parseMatlabRelease(curVer((ind + 2):(numel(curVer) - 1)));
-
- [minY, minAb] = parseMatlabRelease(min);
- [maxY, maxAb] = parseMatlabRelease(max);
-
- inInterval = orderedComparison(minY, minAb, maxY, maxAb, year, ab);
-else % perform comparison with respect to version number
- [major, minor] = parseMatlabVersion(curVer);
- [minMajor, minMinor] = parseMatlabVersion(min);
- [maxMajor, maxMinor] = parseMatlabVersion(max);
-
- inInterval = orderedComparison(minMajor, minMinor, maxMajor, maxMinor, major, minor);
-end
-
- function [year, ab] = parseMatlabRelease(str)
- if (str == Inf)
- year = Inf; ab = Inf;
- elseif (str == -Inf)
- year = -Inf; ab = -Inf;
- else
- year = str2num(str(1:4));
- ab = str(5);
- end
- end
-
- function [major, minor] = parseMatlabVersion(ver)
- if (ver == Inf)
- major = Inf; minor = Inf;
- elseif (ver == -Inf)
- major = -Inf; minor = -Inf;
- elseif (isnumeric(ver))
- major = floor(ver);
- minor = int8((ver - floor(ver)) * 10);
- else % ver is string (e.g. '7.10'), parse accordingly
- [major, rest] = strtok(ver, '.');
- major = str2num(major);
- minor = str2num(strtok(rest, '.'));
- end
- end
-
-% checks if testA is in interval (lowerA,upperA); if at edges, checks if testB is in interval (lowerB,upperB).
- function inInterval = orderedComparison(lowerA, lowerB, upperA, upperB, testA, testB)
- if (testA < lowerA || testA > upperA)
- inInterval = false;
- else
- inInterval = true;
- if (testA == lowerA)
- inInterval = inInterval && (testB >= lowerB);
- end
-
- if (testA == upperA)
- inInterval = inInterval && (testB <= upperB);
- end
- end
- end
-
-end % function
diff --git a/external/fieldtrip/utilities/private/mxSerialize.m b/external/fieldtrip/utilities/private/mxSerialize.m
index e579cee7..334956be 100644
--- a/external/fieldtrip/utilities/private/mxSerialize.m
+++ b/external/fieldtrip/utilities/private/mxSerialize.m
@@ -24,9 +24,9 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: mxSerialize.m 10026 2014-12-08 18:07:07Z eelspa $
+% $Id: mxSerialize.m 10458 2015-06-18 19:53:31Z roboos $
-if matlabversion(-Inf, '2013b') % older than 2014a
+if ft_platform_supports('libmx_c_interface') % older than 2014a
% use the original implementation of the mex file
argout = mxSerialize_c(argin);
else
diff --git a/external/fieldtrip/utilities/private/parameterselection.m b/external/fieldtrip/utilities/private/parameterselection.m
index 052f0cb2..b45aaae9 100644
--- a/external/fieldtrip/utilities/private/parameterselection.m
+++ b/external/fieldtrip/utilities/private/parameterselection.m
@@ -29,7 +29,7 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: parameterselection.m 9767 2014-08-06 09:51:28Z eelspa $
+% $Id: parameterselection.m 10698 2015-09-28 16:55:45Z roboos $
if ischar(param)
param = {param}; % it should be a cell-array
@@ -107,6 +107,8 @@
if nels==prod(dim),
select{end+1} = param{i};
end
+ elseif isfield(data, 'dim') && numel(dim)>3 && isequal(dim(1:3), data.dim(1:3))
+ select{end+1} = param{i};
end
end
end
diff --git a/external/fieldtrip/utilities/private/ptriproj.mexw32 b/external/fieldtrip/utilities/private/ptriproj.mexw32
index d5fd2caf..1c274de1 100755
Binary files a/external/fieldtrip/utilities/private/ptriproj.mexw32 and b/external/fieldtrip/utilities/private/ptriproj.mexw32 differ
diff --git a/external/fieldtrip/utilities/private/ptriproj.mexw64 b/external/fieldtrip/utilities/private/ptriproj.mexw64
index abc1fdcd..997761e6 100755
Binary files a/external/fieldtrip/utilities/private/ptriproj.mexw64 and b/external/fieldtrip/utilities/private/ptriproj.mexw64 differ
diff --git a/external/fieldtrip/utilities/private/randomseed.m b/external/fieldtrip/utilities/private/randomseed.m
index 6c5fe20b..fc60bf09 100644
--- a/external/fieldtrip/utilities/private/randomseed.m
+++ b/external/fieldtrip/utilities/private/randomseed.m
@@ -1,19 +1,22 @@
-function state=randomseed(setseed)
-% randomseed(seedval)
+function state = randomseed(setseed)
+
+% RANDOMSEED retrieves or sets the random seed, taking into account the different
+% MATLAB version specific methods
%
-% Sets the use of rand/randn/randi to specific state/seed,
-% taking into account the different Matlab version specific methods
+% Use as
+% state = randomseed(setseed)
%
% INPUT
-% setseed: [] does not reset the state, but saves out the state for future use
+% setseed [] does not reset the state, but saves out the state for future use
% integer seed value to set to specifc state
% state vector state value (vector) output from previous call to setting the state
%
% OUTPUT
% state vector of current state (or seed only)
-% can be used as input 'setseed' to reset to same state
+%
+% The output can be used as input re-create the same random number sequence
-% Johanna Zumer (2011)
+% Copyright (C) 2011, Johanna Zumer
%
% This file is part of FieldTrip, see http://www.ru.nl/neuroimaging/fieldtrip
% for the documentation and details.
@@ -31,69 +34,86 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
-if ischar(setseed)
- if strcmp(setseed, 'no')
- setseed = [];
- elseif strcmp(setseed, 'yes')
- setseed = sum(100*clock);
- else
- error('unknown specification for a random seed');
- end
+if nargin<1
+ setseed = [];
end
+state = [];
-if isempty(setseed) % save out rand state for later use
- if matlabversion(-Inf,'7.3')
- rand('twister',sum(100*clock)) % can fail otherwise, if first time rand is called per matlab session
- state=rand('twister');
- elseif matlabversion('7.4','7.6')
- state=rand('twister');
- elseif matlabversion('7.7','7.11')
+if isempty(setseed)
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ % save out rand state for later use
+
+ if ~ft_platform_supports('randomized_PRNG_on_startup')
+ % old MATLAB versions (< = v7.3)
+ rand('twister', sum(100*clock)) % can fail otherwise, if first time rand is called per MATLAB session
+ end
+
+ if ft_platform_supports('rng')
+ % Recent MATLAB versions
+ s = rng;
+ state = s.State;
+ elseif ft_platform_supports('rand-state')
+ % GNU Octave
+ state = rand('state');
+ elseif ft_platform_supports('RandStream.setDefaultStream')
+ % older MATLAB versions
stream = RandStream.getDefaultStream;
- state=stream.State;
- elseif matlabversion('7.12',Inf)
- s=rng;
- state=s.State;
+ state = stream.State;
+ else
+ % fallback
+ state = rand('twister');
end
-else % seedval is actual random seed value set by user, OR saved state
- if matlabversion(-Inf,'7.6')
+
+else
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ % seedval is the random seed value specified by the user
+
+ if ft_platform_supports('rng')
+ % Recent MATLAB versions
if isscalar(setseed)
- state=rand('twister',setseed);
+ rng(setseed, 'twister')
+ s = rng;
elseif isnumeric(setseed)
- % use only the first number of the array
- fprintf('the requested random seed seems an array, but only a scalar is supported in this version of MATLAB, using the first entry\n');
- state=rand('twister',setseed(1));
+ s.Type = 'twister';
+ s.State = setseed;
+ s.Seed = 0;
+ rng(s);
else
- state=rand('twister');
+ s.Type = 'Legacy';
+ s.Seed = 'Not applicable';
+ s.State = setseed;
+ rng(s);
end
- elseif matlabversion('7.7','7.11')
+ state = s.State;
+
+ elseif ft_platform_supports('rand-state')
+ % GNU Octave
if isscalar(setseed)
- stream=RandStream('mt19937ar','Seed',setseed);
- elseif isnumeric(setseed)
- % use only the first number of the array
- fprintf('the requested random seed seems an array, but only a scalar is supported in this version of MATLAB, using the first entry\n');
- stream=RandStream('mt19937ar','Seed',setseed(1));
+ rand('seed', setseed);
else
- stream=RandStream.getDefaultStream;
- stream.State=setseed;
+ rand('state', setseed);
end
- RandStream.setDefaultStream(stream);
- state=stream.State;
- elseif matlabversion('7.12',Inf)
+
+ elseif ft_platform_supports('RandStream.setDefaultStream')
+ % older MATLAB versions
if isscalar(setseed)
- rng(setseed,'twister')
- s=rng;
- elseif isnumeric(setseed)
- s.Type='twister';
- s.State=setseed;
- s.Seed=0;
- rng(s);
+ stream = RandStream('mt19937ar', 'Seed', setseed);
else
- s.Type='Legacy';
- s.Seed='Not applicable';
- s.State=setseed;
- rng(s);
+ stream = RandStream.getDefaultStream;
+ stream.State = setseed;
end
- state=s.State;
+ RandStream.setDefaultStream(stream);
+ state = stream.State;
+ else
+ % fallback
+ rand('twister', setseed);
+ state = rand('twister');
end
-end;
+
+end % set or get the seed
+if nargin && nargout && isempty(state)
+ % the output should be the same as the user-supplied input
+ % this will guarantee tehe same random sequence repeatedly
+ state = setseed;
+end
\ No newline at end of file
diff --git a/external/fieldtrip/utilities/private/scalingfactor.m b/external/fieldtrip/utilities/private/scalingfactor.m
deleted file mode 100644
index b2fddb4e..00000000
--- a/external/fieldtrip/utilities/private/scalingfactor.m
+++ /dev/null
@@ -1,238 +0,0 @@
-function factor = scalingfactor(old, new)
-
-% SCALINGFACTOR determines the scaling factor from old to new units.
-%
-% Use as
-% factor = scalingfactor(old, new)
-% where old and new are strings that specify the units.
-%
-% For example
-% scalingfactor('m', 'cm') % returns 100
-% scalingfactor('V', 'uV') % returns 1000
-% scalingfactor('T/cm', 'fT/m') % returns 10^15 divided by 10^-2, which is 10^17
-% scalingfactor('cm^2', 'mm^2') % returns 100
-% scalingfactor('1/ms', 'Hz') % returns 1000
-%
-% The following fundamental units are supported
-% metre m length l (a lowercase L), x, r L
-% kilogram kg mass m M
-% second s time t T
-% ampere A electric current I (an uppercase i) I
-% kelvin K thermodynamic temperature T #
-% mole mol amount of substance n N
-% candela cd luminous intensity Iv (an uppercase i with lowercase non-italicized v subscript) J
-%
-% The following derived units are supported
-% hertz Hz frequency 1/s T-1
-% radian rad angle m/m dimensionless
-% steradian sr solid angle m2/m2 dimensionless
-% newton N force, weight kg#m/s2 M#L#T-2
-% pascal Pa pressure, stress N/m2 M#L-1#T-2
-% joule J energy, work, heat N#m = C#V = W#s M#L2#T-2
-% coulomb C electric charge or quantity of electricity s#A T#I
-% volt V voltage, electrical potential difference, electromotive force W/A = J/C M#L2#T-3#I-1
-% farad F electric capacitance C/V M-1#L-2#T4#I2
-% siemens S electrical conductance 1/# = A/V M-1#L-2#T3#I2
-% weber Wb magnetic flux J/A M#L2#T-2#I-1
-% tesla T magnetic field strength V#s/m2 = Wb/m2 = N/(A#m) M#T-2#I-1
-% henry H inductance V#s/A = Wb/A M#L2#T-2#I-2
-% lumen lm luminous flux cd#sr J
-% lux lx illuminance lm/m2 L-2#J
-% becquerel Bq radioactivity (decays per unit time) 1/s T-1
-% gray Gy absorbed dose (of ionizing radiation) J/kg L2#T-2
-% sievert Sv equivalent dose (of ionizing radiation) J/kg L2#T-2
-% katal kat catalytic activity mol/s T-1#N
-%
-% The following derived units are not supported due to potential confusion
-% between their ascii character representation
-% ohm # electric resistance, impedance, reactance V/A M#L2#T-3#I-2
-% watt W power, radiant flux J/s = V#A M#L2#T-3
-% degree Celsius °C temperature relative to 273.15 K K ?
-%
-% See also http://en.wikipedia.org/wiki/International_System_of_Units
-
-% Copyright (C) 2012, Robert Oostenveld
-%
-% This file is part of FieldTrip, see http://www.ru.nl/neuroimaging/fieldtrip
-% for the documentation and details.
-%
-% FieldTrip is free software: you can redistribute it and/or modify
-% it under the terms of the GNU General Public License as published by
-% the Free Software Foundation, either version 3 of the License, or
-% (at your option) any later version.
-%
-% FieldTrip is distributed in the hope that it will be useful,
-% but WITHOUT ANY WARRANTY; without even the implied warranty of
-% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-% GNU General Public License for more details.
-%
-% You should have received a copy of the GNU General Public License
-% along with FieldTrip. If not, see .
-%
-% $Id: scalingfactor.m 9631 2014-06-16 10:55:43Z vlalit $
-
-persistent previous_old previous_new previous_factor
-
-if isempty(previous_old)
- previous_old = {};
- previous_new = {};
- previous_factor = [];
-end
-
-if ~isequal(class(old), class(new))
- error('the input arguments should be of the same class');
-end
-
-if iscell(old)
- factor = cellfun(@scalingfactor, old(:), new(:));
- return
-end
-
-cachehit = strcmp(old, previous_old) & strcmp(new, previous_new);
-if any(cachehit)
- factor = previous_factor(cachehit);
- return
-end
-
-if isequal(old, new)
- % this applies regardless of the units
- factor = 1;
- return
-end
-
-unit = {'m' 'g' 's' 'A' 'K' 'mol' 'cd' 'Hz' 'rad' 'sr' 'N' 'Pa' 'J' 'C' 'V' 'F' 'S' 'Wb' 'T' 'H' 'lm' 'lx' 'Bq' 'Gy' 'Sv' 'kat'};
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% the following section pertains to checking that units are compatible
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-% each of the fundamental units is represented by a prime number
-m = 2;
-kg = 3; g = 3; % besides representing kg, also represent g to facilitate the processing further down
-s = 5;
-A = 7;
-K = 11;
-mol = 13;
-cd = 17;
-unknown = -1;
-
-% each of the derives units is represented by a product and/or ratio of prime numbers
-Hz = 1/s;
-rad = nan; % this is dimensionless, cannot be converted
-sr = nan; % this is dimensionless, cannot be converted
-N = kg*m/s^2;
-Pa = N/m^2;
-J = N*m;
-C = s*A;
-V = J/C;
-F = C/V;
-S = A/V;
-Wb = J/A;
-T = Wb/m^2;
-H = V*s/A;
-lm = cd*sr;
-lx = lm/m^2;
-Bq = 1/s;
-Gy = J/kg;
-Sv = J/kg;
-kat = mol/s;
-
-% deal with all possible prefixes
-for i=1:length(unit)
- eval(sprintf('d%s = %s;', unit{i}, unit{i}));
- eval(sprintf('c%s = %s;', unit{i}, unit{i}));
- eval(sprintf('m%s = %s;', unit{i}, unit{i}));
- eval(sprintf('u%s = %s;', unit{i}, unit{i})); % note that u is used for micro
- eval(sprintf('n%s = %s;', unit{i}, unit{i}));
- eval(sprintf('p%s = %s;', unit{i}, unit{i}));
- eval(sprintf('f%s = %s;', unit{i}, unit{i}));
- eval(sprintf('a%s = %s;', unit{i}, unit{i}));
- eval(sprintf('z%s = %s;', unit{i}, unit{i}));
- eval(sprintf('y%s = %s;', unit{i}, unit{i}));
-
- eval(sprintf('da%s = %s;', unit{i}, unit{i}));
- eval(sprintf('h%s = %s;', unit{i}, unit{i}));
- eval(sprintf('k%s = %s;', unit{i}, unit{i}));
- eval(sprintf('M%s = %s;', unit{i}, unit{i}));
- eval(sprintf('G%s = %s;', unit{i}, unit{i}));
- eval(sprintf('T%s = %s;', unit{i}, unit{i}));
- eval(sprintf('P%s = %s;', unit{i}, unit{i}));
- eval(sprintf('E%s = %s;', unit{i}, unit{i}));
- eval(sprintf('Z%s = %s;', unit{i}, unit{i}));
- eval(sprintf('Y%s = %s;', unit{i}, unit{i}));
-end
-
-eval(sprintf('oldunit = %s;', old));
-eval(sprintf('newunit = %s;', new));
-if ~isequal(oldunit, newunit)
- error('cannot convert %s to %s', old, new);
-end
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% the following pertains to determining the scaling factor
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-% fundamental units
-m = 1;
-kg = 1; g = 0.001; % besides representing kg, also represent g to facilitate the processing further down
-s = 1;
-A = 1;
-K = 1;
-mol = 1;
-cd = 1;
-
-% derived units
-Hz = 1;
-rad = 1;
-sr = 1;
-N = 1;
-Pa = 1;
-J = 1;
-C = 1;
-V = 1;
-F = 1;
-S = 1;
-Wb = 1;
-T = 1;
-H = 1;
-lm = 1;
-lx = 1;
-Bq = 1;
-Gy = 1;
-Sv = 1;
-kat = 1;
-
-% deal with all possible prefixes
-for i=1:length(unit)
- eval(sprintf('d%s = 1e-1 * %s;', unit{i}, unit{i}));
- eval(sprintf('c%s = 1e-2 * %s;', unit{i}, unit{i}));
- eval(sprintf('m%s = 1e-3 * %s;', unit{i}, unit{i}));
- eval(sprintf('u%s = 1e-6 * %s;', unit{i}, unit{i})); % note that u is used for micro
- eval(sprintf('n%s = 1e-9 * %s;', unit{i}, unit{i}));
- eval(sprintf('p%s = 1e-12 * %s;', unit{i}, unit{i}));
- eval(sprintf('f%s = 1e-15 * %s;', unit{i}, unit{i}));
- eval(sprintf('a%s = 1e-18 * %s;', unit{i}, unit{i}));
- eval(sprintf('z%s = 1e-21 * %s;', unit{i}, unit{i}));
- eval(sprintf('y%s = 1e-24 * %s;', unit{i}, unit{i}));
-
- eval(sprintf('da%s = 1e1 * %s;', unit{i}, unit{i}));
- eval(sprintf('h%s = 1e2 * %s;', unit{i}, unit{i}));
- eval(sprintf('k%s = 1e3 * %s;', unit{i}, unit{i}));
- eval(sprintf('M%s = 1e6 * %s;', unit{i}, unit{i}));
- eval(sprintf('G%s = 1e9 * %s;', unit{i}, unit{i}));
- eval(sprintf('T%s = 1e12 * %s;', unit{i}, unit{i}));
- eval(sprintf('P%s = 1e15 * %s;', unit{i}, unit{i}));
- eval(sprintf('E%s = 1e18 * %s;', unit{i}, unit{i}));
- eval(sprintf('Z%s = 1e21 * %s;', unit{i}, unit{i}));
- eval(sprintf('Y%s = 1e24 * %s;', unit{i}, unit{i}));
-end
-
-eval(sprintf('old2si = %s;', old));
-eval(sprintf('new2si = %s;', new));
-
-factor = old2si/new2si;
-
-% remember the input args and the result, this will speed up the next call if the input is the same
-previous_old{end+1} = old;
-previous_new{end+1} = new;
-previous_factor(end+1) = factor;
diff --git a/external/fieldtrip/utilities/private/unparcellate.m b/external/fieldtrip/utilities/private/unparcellate.m
index acb33771..b5b0e822 100755
--- a/external/fieldtrip/utilities/private/unparcellate.m
+++ b/external/fieldtrip/utilities/private/unparcellate.m
@@ -29,56 +29,78 @@
% If the input was bivariate data with a labelcmb, an optional second
% output argument gives a list of the reference parcels.
+% Undocumented input key-value pair:
+% output = 'data' (default), or 'projection matrix', only works without 'labelcmb' in input
+
+output = ft_getopt(varargin, 'output', 'data');
+
if isstruct(data)
tmp = getsubfield(data, parameter);
elseif size(parameter,2)==1
tmp = data;
clear data;
data.label = parameter;
+ data = setsubfield(data, parameter, tmp);
elseif size(parameter,2)==2
% this contains labelcmb e.g. pairwise granger
tmp = data;
clear data;
data.labelcmb = parameter;
+ data = setsubfield(data, parameter, tmp);
end
if isfield(data, 'label')
% the data is chan_xxx or chan_chan_xxx
- dimord = getdimord(data, parameter);
- dimtok = tokenize(dimord, '_');
- dimsiz = getdimsiz(data, parameter);
- % replace the number of parcels by the number of vertices in a parcel
- dimsiz(strcmp(dimtok, 'chan')) = size(parcellation.pos,1);
-
- fun = nan(dimsiz);
-
- [parcelindx, chanindx] = match_str(parcellation.([parcelparam,'label']), data.label);
-
- if numel(dimtok)>1 && strcmp(dimtok{1}, 'chan') && strcmp(dimtok{2}, 'chan')
- % chan_chan_xxx
- for i=1:numel(parcelindx)
- for j=1:numel(parcelindx)
- p1 = parcellation.(parcelparam)==parcelindx(i);
- p2 = parcellation.(parcelparam)==parcelindx(j);
- c1 = chanindx(i);
- c2 = chanindx(j);
- fun(p1,p2,:) = repmat(tmp(c1,c2,:), [sum(p1) sum(p2) 1]);
+ switch output
+ case 'data'
+ dimord = getdimord(data, parameter);
+ dimtok = tokenize(dimord, '_');
+ dimsiz = getdimsiz(data, parameter);
+ % replace the number of parcels by the number of vertices in a parcel
+ dimsiz(strcmp(dimtok, 'chan')) = size(parcellation.pos,1);
+
+ fun = nan(dimsiz);
+
+ [parcelindx, chanindx] = match_str(parcellation.([parcelparam,'label']), data.label);
+
+ if strcmp(dimtok{1}, 'chan') && strcmp(dimtok{2}, 'chan')
+ % chan_chan_xxx
+ for i=1:numel(parcelindx)
+ for j=1:numel(parcelindx)
+ p1 = parcellation.(parcelparam)==parcelindx(i);
+ p2 = parcellation.(parcelparam)==parcelindx(j);
+ c1 = chanindx(i);
+ c2 = chanindx(j);
+ fun(p1,p2,:) = repmat(tmp(c1,c2,:), [sum(p1) sum(p2) 1]);
+ end
+ end
+ elseif strcmp(dimtok{1}, 'chan')
+ % chan_xxx
+ for i=1:numel(parcelindx)
+ p1 = parcellation.(parcelparam)==parcelindx(i);
+ c1 = chanindx(i);
+ fun(p1,:) = repmat(tmp(c1,:), [sum(p1) 1]);
+ end
end
- end
-
- elseif strcmp(dimtok{1}, 'chan')
- % chan_xxx
- for i=1:numel(parcelindx)
- p1 = parcellation.(parcelparam)==parcelindx(i);
- c1 = chanindx(i);
- fun(p1,:) = repmat(tmp(c1,:), [sum(p1) 1]);
- end
-
+ varargout{1} = fun;
+
+ case 'projection matrix'
+ [parcelindx, chanindx] = match_str(parcellation.([parcelparam,'label']), data.label);
+ ix = zeros(0,1);
+ iy = zeros(0,1);
+ for i=1:numel(parcelindx)
+ ix = cat(1,ix,find(parcellation.(parcelparam)==parcelindx(i)));
+ iy = cat(1,iy,ones(sum(parcellation.(parcelparam)==parcelindx(i)),1).*chanindx(i));
+ end
+ fun = sparse(ix,iy,ones(numel(ix),1));
+
+ varargout{1} = fun;
+ varargout{2} = data.label(chanindx);
+
+ otherwise
end
- varargout{1} = fun;
-
elseif isfield(data, 'labelcmb')
% bivariate data
diff --git a/external/fieldtrip/utilities/private/warning_once.m b/external/fieldtrip/utilities/private/warning_once.m
deleted file mode 100644
index 9cede9d8..00000000
--- a/external/fieldtrip/utilities/private/warning_once.m
+++ /dev/null
@@ -1,235 +0,0 @@
-function [ws warned] = warning_once(varargin)
-%
-% WARNING_ONCE will throw a warning for every unique point in the
-% stacktrace only, e.g. in a for-loop a warning is thrown only once.
-%
-% Use as one of the following
-% warning_once(string)
-% warning_once(id, string)
-% Alternatively, you can use warning_once using a timeout
-% warning_once(string, timeout)
-% warning_once(id, string, timeout)
-% where timeout should be inf if you don't want to see the warning ever
-% again.
-%
-% Use as warning_once('-clear') to clear old warnings from the current
-% stack
-%
-% It can be used instead of the MATLAB built-in function WARNING, thus as
-% s = warning_once(...)
-% or as
-% warning_once(s)
-% where s is a structure with fields 'identifier' and 'state', storing the
-% state information. In other words, warning_once accepts as an input the
-% same structure it returns as an output. This returns or restores the
-% states of warnings to their previous values.
-%
-% It can also be used as
-% [s w] = warning_once(...)
-% where w is a boolean that indicates whether a warning as been thrown or not.
-%
-% Please note that you can NOT use it like this
-% warning_once('the value is %d', 10)
-% instead you should do
-% warning_once(sprintf('the value is %d', 10))
-
-% Copyright (C) 2012, Robert Oostenveld
-% Copyright (C) 2013, Robert Oostenveld, J?rn M. Horschig
-%
-% This file is part of FieldTrip, see http://www.ru.nl/neuroimaging/fieldtrip
-% for the documentation and details.
-%
-% FieldTrip is free software: you can redistribute it and/or modify
-% it under the terms of the GNU General Public License as published by
-% the Free Software Foundation, either version 3 of the License, or
-% (at your option) any later version.
-%
-% FieldTrip is distributed in the hope that it will be useful,
-% but WITHOUT ANY WARRANTY; without even the implied warranty of
-% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-% GNU General Public License for more details.
-%
-% You should have received a copy of the GNU General Public License
-% along with FieldTrip. If not, see .
-%
-% $Id: warning_once.m 10001 2014-12-02 09:04:27Z roboos $
-
-global ft_default
-
-if nargin < 1
- error('You need to specify at least a warning message');
-end
-
-warned = false;
-if isstruct(varargin{1})
- warning(varargin{1});
- return;
-end
-
-if ~isfield(ft_default, 'warning')
- ft_default.warning.stopwatch = [];
- ft_default.warning.identifier = [];
-end
-
-% put the arguments we will pass to warning() in this cell array
-warningArgs = {};
-
-if nargin==3
- % calling syntax (id, msg, timeout)
-
- warningArgs = varargin(1:2);
- msg = warningArgs{2};
- timeout = varargin{3};
- fname = [warningArgs{1} '_' warningArgs{2}];
-
-elseif nargin==2 && isnumeric(varargin{2})
- % calling syntax (msg, timeout)
-
- warningArgs = varargin(1);
- msg = warningArgs{1};
- timeout = varargin{2};
- fname = warningArgs{1};
-
-elseif nargin==2 && ~isnumeric(varargin{2})
- % calling syntax (id, msg)
-
- warningArgs = varargin(1:2);
- msg = warningArgs{2};
- timeout = inf;
- fname = [warningArgs{1} '_' warningArgs{2}];
-
-elseif nargin==1
- % calling syntax (msg)
-
- warningArgs = varargin(1);
- msg = warningArgs{1};
- timeout = inf; % default timeout in seconds
- fname = [warningArgs{1}];
-
-end
-
-if isempty(timeout)
- error('Timeout ill-specified');
-end
-
-if timeout ~= inf
- fname = decomma(fixname(fname)); % make a nice string that is allowed as structure fieldname
- if length(fname) > 63 % MATLAB max name
- fname = fname(1:63);
- end
- line = [];
-else
- % here, we create the fieldname functionA.functionB.functionC...
- [tmpfname ft_default.warning.identifier line] = fieldnameFromStack(ft_default.warning.identifier);
- if ~isempty(tmpfname)
- fname = tmpfname;
- clear tmpfname;
- end
-end
-
-if nargin==1 && ischar(varargin{1}) && strcmp('-clear', varargin{1})
- if strcmp(fname, '-clear') % reset all fields if called outside a function
- ft_default.warning.identifier = [];
- ft_default.warning.stopwatch = [];
- else
- if issubfield(ft_default.warning.identifier, fname)
- ft_default.warning.identifier = rmsubfield(ft_default.warning.identifier, fname);
- end
- end
- return;
-end
-
-% and add the line number to make this unique for the last function
-fname = horzcat(fname, line);
-
-if ~issubfield('ft_default.warning.stopwatch', fname)
- ft_default.warning.stopwatch = setsubfield(ft_default.warning.stopwatch, fname, tic);
-end
-
-now = toc(getsubfield(ft_default.warning.stopwatch, fname)); % measure time since first function call
-
-if ~issubfield(ft_default.warning.identifier, fname) || ...
- (issubfield(ft_default.warning.identifier, fname) && now>getsubfield(ft_default.warning.identifier, [fname '.timeout']))
-
- % create or reset field
- ft_default.warning.identifier = setsubfield(ft_default.warning.identifier, fname, []);
-
- % warning never given before or timed out
- ws = warning(warningArgs{:});
- ft_default.warning.identifier = setsubfield(ft_default.warning.identifier, [fname '.timeout'], now+timeout);
- ft_default.warning.identifier = setsubfield(ft_default.warning.identifier, [fname '.ws'], msg);
- warned = true;
-else
-
- % the warning has been issued before, but has not timed out yet
- ws = getsubfield(ft_default.warning.identifier, [fname '.ws']);
-
-end
-
-end % function warning_once
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% helper functions
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-function name = decomma(name)
-name(name==',')=[];
-end % function
-
-function [fname ft_previous_warnings line] = fieldnameFromStack(ft_previous_warnings)
-% stack(1) is this function, stack(2) is warning_once
-stack = dbstack('-completenames');
-if size(stack) < 3
- fname = [];
- line = [];
- return;
-end
-i0 = 3;
-% ignore ft_preamble
-while strfind(stack(i0).name, 'ft_preamble')
- i0=i0+1;
-end
-
-fname = horzcat(fixname(stack(end).name));
-if ~issubfield(ft_previous_warnings, fixname(stack(end).name))
- ft_previous_warnings.(fixname(stack(end).name)) = []; % iteratively build up structure fields
-end
-
-
-for i=numel(stack)-1:-1:(i0)
- % skip postamble scripts
- if strncmp(stack(i).name, 'ft_postamble', 12)
- break;
- end
-
- fname = horzcat(fname, '.', horzcat(fixname(stack(i).name))); % , stack(i).file
- if ~issubfield(ft_previous_warnings, fname) % iteratively build up structure fields
- setsubfield(ft_previous_warnings, fname, []);
- end
-end
-
-% line of last function call
-line = ['.line', int2str(stack(i0).line)];
-end
-
-% function outcome = issubfield(strct, fname)
-% substrindx = strfind(fname, '.');
-% if numel(substrindx) > 0
-% % separate the last fieldname from all former
-% outcome = eval(['isfield(strct.' fname(1:substrindx(end)-1) ', ''' fname(substrindx(end)+1:end) ''')']);
-% else
-% % there is only one fieldname
-% outcome = isfield(strct, fname);
-% end
-% end
-
-% function strct = rmsubfield(strct, fname)
-% substrindx = strfind(fname, '.');
-% if numel(substrindx) > 0
-% % separate the last fieldname from all former
-% strct = eval(['rmfield(strct.' fname(1:substrindx(end)-1) ', ''' fname(substrindx(end)+1:end) ''')']);
-% else
-% % there is only one fieldname
-% strct = rmfield(strct, fname);
-% end
-% end
diff --git a/external/fieldtrip/utilities/renamefields.m b/external/fieldtrip/utilities/renamefields.m
new file mode 100644
index 00000000..84d2e5f0
--- /dev/null
+++ b/external/fieldtrip/utilities/renamefields.m
@@ -0,0 +1,56 @@
+function b = renamefields(a, old, new)
+
+% RENAMEFIELDS renames a selection of the fields in a structure
+%
+% Use as
+% b = renamefields(a, old, new);
+% which renames the fields with the old name to the new name. Fields that
+% are specified but not present will be silently ignored.
+%
+% See also COPYFIELDS, KEEPFIELDS, REMOVEFIELDS
+
+% Copyright (C) 2014, Robert Oostenveld
+%
+% This file is part of FieldTrip, see http://www.ru.nl/neuroimaging/fieldtrip
+% for the documentation and details.
+%
+% FieldTrip is free software: you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation, either version 3 of the License, or
+% (at your option) any later version.
+%
+% FieldTrip is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU General Public License
+% along with FieldTrip. If not, see .
+%
+% $Id: renamefields.m 11062 2016-01-15 11:27:50Z roboos $
+
+if isempty(a)
+ % this prevents problems if a is an empty double, i.e. []
+ return
+end
+
+% these should be cell-arrays
+if ischar(old)
+ old = {old};
+end
+if ischar(new)
+ new = {new};
+end
+
+if length(old)~=length(new)
+ error('the number of field names does not match between old and new');
+end
+
+% keep the fields that were not mentioned
+b = keepfields(a, setdiff(fieldnames(a), old));
+% copy the fields over with their new name
+for i=1:length(old)
+ if isfield(a, old{i});
+ b.(new{i}) = a.(old{i});
+ end
+end
diff --git a/external/fieldtrip/utilities/tokenize.m b/external/fieldtrip/utilities/tokenize.m
index 1824f56e..62cbce95 100644
--- a/external/fieldtrip/utilities/tokenize.m
+++ b/external/fieldtrip/utilities/tokenize.m
@@ -36,11 +36,13 @@
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see .
%
-% $Id: tokenize.m 8771 2013-11-12 13:55:00Z roboos $
+% $Id: tokenize.m 10785 2015-10-17 09:41:47Z roboos $
% these are for remembering the type on subsequent calls with the same input arguments
persistent previous_argin previous_argout
+str = str(:)';
+
if nargin<2
sep = [9:13 32]; % White space characters
end
@@ -56,9 +58,14 @@
return
end
-tok = {};
-f = find(ismember(str, sep));
+if numel(sep)==1
+ f = find(str==sep);
+else
+ f = find(ismember(str, sep));
+end
f = [0, f, length(str)+1];
+
+tok = cell(1, length(f)-1);
for i=1:(length(f)-1)
tok{i} = str((f(i)+1):(f(i+1)-1));
end
diff --git a/help/index.html b/help/index.html
index 980a58d7..3cad9d89 100644
--- a/help/index.html
+++ b/help/index.html
@@ -47,7 +47,7 @@
Welcome to SPM12
of the Licence, or (at your option) any later version.