-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeCSVTable.m
More file actions
61 lines (49 loc) · 1.43 KB
/
makeCSVTable.m
File metadata and controls
61 lines (49 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
% Save as CSV, open in Excel, then copy into word... (wish there
% was a simpler way)
% columnHeader is Ncols + 1, first column label the row headers
function makeCSVTable(fileName, columnHeader,rowHeader,matrix,formatStr)
% Just double check before writing file
assert(strcmpi(fileName(end-2:end),'csv'))
assert(numel(columnHeader) == size(matrix,2)+1)
assert(numel(rowHeader) == size(matrix,1))
assert(~iscell(formatStr) | numel(formatStr) == size(matrix,2))
% Lets get cracking
fid = fopen(fileName,'w');
for i = 1:numel(columnHeader)
if(i == 1)
fprintf(fid,'%s', columnHeader{i});
else
fprintf(fid,', %s', columnHeader{i});
end
end
fprintf(fid,'\n');
for i = 1:numel(rowHeader)
% Left most column is row headers
fprintf(fid,'%s',rowHeader{i});
for j = 1:size(matrix,2)
if(islogical(matrix(i,j)))
if(matrix(i,j))
fprintf(fid,',•')
else
fprintf(fid,', ')
end
else
if(iscell(formatStr))
if(strcmpri(formatStr,'binary'))
if(matrix(i,j))
fprintf(fid,',•')
else
fprintf(fid,', ')
end
else
fprintf(fid, [',' formatStr{j}], matrix(i,j));
end
else
fprintf(fid, [',' formatStr], matrix(i,j));
end
end
end
fprintf(fid,'\n');
end
fclose(fid);
end