-
Notifications
You must be signed in to change notification settings - Fork 10
/
snpm_list.m
41 lines (35 loc) · 1.6 KB
/
snpm_list.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function varargout = snpm_list(varargin)
% Support function for snpm_pp.m
% FORMAT spm_list('CSVList',TabDat,ofile)
%
% Tiny modification to spm_list to allow different number of columns in TabDat
%_______________________________________________________________________
% Copyright (C) 2016 The University of Warwick
% snnpm_list.m, based on spm_list.m 6903
% Thomas Nichols
switch lower(varargin{1})
%======================================================================
case 'csvlist' %-Export table to comma-separated values file
%======================================================================
% FORMAT snpm_list('CSVList',TabDat,ofile)
if nargin<2, error('Not enough input arguments.'); end
TabDat = varargin{2};
if nargin == 3, ofile = varargin{3};
else, ofile = [tempname '.csv']; end
fid = fopen(ofile,'wt');
ncol=size(TabDat.hdr,2);
fprintf(fid,[repmat('%s,',1,ncol-1) '%d,,,\n'],TabDat.hdr{1,:});
fprintf(fid,[repmat('%s,',1,ncol) '\n'],TabDat.hdr{2,:});
fmt = TabDat.fmt;
[fmt{2,:}] = deal(','); fmt = [fmt{:}];
fmt(end:end+1) = '\n'; fmt = strrep(fmt,' ',',');
for i=1:size(TabDat.dat,1)
fprintf(fid,fmt,TabDat.dat{i,:});
end
fclose(fid);
if nargin == 2, open(ofile); end
%======================================================================
otherwise %-Unknown action string
%======================================================================
error('Unknown action string')
end