/
print_cell.m
42 lines (42 loc) · 1.09 KB
/
print_cell.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
42
function res=print_cell(input,file,linesep,cellsep)
assert(iscell(input),'The input should be a cell')
if nargin < 4
cellsep = '\t';
end
if nargin < 3
linesep = '\n';
end
if exist('file','var') && ~isempty(file)
%%
fid = fopen(file,'w');
for l=1:length(input)
if iscell(input{l})
for i=1:length(input{l})
fprintf(fid,['%s' cellsep],input{l}{i});
end
fprintf(fid,linesep);
else
if size(input,2) > 1
for i=1:size(input,2)
fprintf(fid,'%s ',input{l,i});
end
fprintf(fid,linesep);
else
fprintf(fid,['%s' linesep],input{l});
end
end
end
fclose(fid);
else
res = '';
for l=1:length(input)
if iscell(input{l})
for i=1:length(input{l})
res = [res sprintf([cellsep{1} '%s' cellsep{2}],input{l}{i})];
end
res = [res sprintf(linesep)];
else
res = [res sprintf(['%s' linesep],input{l}(:))];
end
end
end