forked from kndiaye/matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cell2str.m
68 lines (61 loc) · 1.93 KB
/
cell2str.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function t = cell2str(c,sep,s)
%CELL2STR - Convert a cell array into text (i.e. string array)
% [S] = cell2str(C)
%
% Example
% >> celldisp2
%
% See also: celldisp
% Author: K. N'Diaye (kndiaye01<at>yahoo.fr)
% Copyright (C) 2010
% This program 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 2 of the License, or (at your
% option) any later version: http://www.gnu.org/copyleft/gpl.html
%
% ----------------------------- Script History ---------------------------------
% KND 2010-04-01 Creation
%
% ----------------------------- Script History ---------------------------------
%error(nargchk(1,2,nargin,'struct'));
if ~iscell(c),
error('MATLAB:celldisp:notCellArray', 'Must be a cell array.');
end
if nargin<2, sep = {'-' '|' }; end
if nargin<3, s = inputname(1); end
if isempty(s), s = 'ans'; end
for i=1:numel(c),
if iscell(c{i}) && ~isempty(c{i}),
t=sprintf( '%s\n%s\n%s',s,repmat(sep{1}, [1 size(s,2)]), cell2str(c{i},sep,[s subs(i,size(c))]));
else
t=sprintf('%s%s =\n',s,subs(i,size(c)));
if ~isempty(c{i}),
t=sprintf('%s%s',t,);
else
if iscell(c{i})
disp(' {}')
elseif ischar(c{i})
disp(' ''''')
elseif isnumeric(c{i})
disp(' []')
else
[m,n] = size(c{i});
disp(sprintf('%0.f-by-%0.f %s',m,n,class(c{i})))
end
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function s = subs(i,siz)
%SUBS Display subscripts
if length(siz)==2 && any(any(siz==1))
v = cell(1,1);
else
v = cell(size(siz));
end
[v{1:end}] = ind2sub(siz,i);
s = ['{' int2str(v{1})];
for i=2:length(v),
s = [s ',' int2str(v{i})];
end
s = [s '}'];