1 function outStr=
showcell(inpCArr,varargin)
4 throwerror(
'wrongInput',
'This is not a cell array');
7 [~,~,nSpaces,nDigits,isVarNamePrinted,varName,isClassShown,...
8 isAsExpression,nMaxShownArrayElems,...
9 ~,isNDigitsSpec,~,isVarNameSpec]=...
11 {
'nSpaces',
'nDigits',
'printVarName',
'varName',
'showClass',...
12 'asExpression',
'nMaxShownArrayElems';...
13 4,15,
false,[],
false,
false,10;...
14 'isnumeric(x)&&isscalar(x)',
'isnumeric(x)&&isscalar(x)',...
15 'islogical(x)&&isscalar(x)',
'isstring(x)',...
16 'islogical(x)&&isscalar(x)',
'islogical(x)&&isscalar(x)',...
17 'isnumeric(x)&&isscalar(x)&&(fix(x)==x)&&(x>=0)'},0);
20 fNumPrint=@(x)
numArr2str(x,isAsExpression,isClassShown,nDigits);
22 fNumPrint=@(x)
numArr2str(x,isAsExpression,isClassShown);
27 if ~isVarNameSpec&&isVarNamePrinted
34 sizeVec=size(inpCArr);
35 areAllFirstDimsZeros=max(sizeVec)==0;
36 areAnyFirstDimsZeros=min(sizeVec)==0;
38 nRestDims=ndims(inpCArr) - 2;
40 if nRestDims==0&&areAllFirstDimsZeros
42 lineStrList={
'cell.empty(0,0)'};
48 if areAnyFirstDimsZeros
52 fCharPrint,fCellPrint,...
53 true,nMaxShownArrayElems);
56 if areAnyFirstDimsZeros
57 dimList=arrayfun(@(x)sprintf(
'%d',x),sizeVec,...
58 'UniformOutput',
false);
59 lineStrList={sprintf(
'Empty cell array: %s\n',...
63 indDimVecList=cell(nRestDims,1);
65 nHigherDimElems=prod(sizeVec(3:end));
67 [indDimVecList{:}]=ind2sub(sizeVec(3:end),...
68 transpose(1:nHigherDimElems));
69 indMat=horzcat(indDimVecList{:});
70 indElemVecList=mat2cell(indMat,...
71 ones(1,nHigherDimElems),nRestDims);
73 isElemNumPrinted=
true;
76 isElemNumPrinted=
false;
79 listOflineStrList=cell(1,nHigherDimElems);
80 for iHigherDimElem=1:nHigherDimElems
81 curPartCMat=inpCArr(:,:,iHigherDimElem);
84 fCharPrint,fCellPrint,
false,nMaxShownArrayElems);
86 elemNumStr=[
'(:,:',sprintf(
',%d',...
87 indElemVecList{iHigherDimElem}),
')'];
88 nSymbols=numel(elemNumStr);
89 blankStubStr=
repmat(
' ',1,nSymbols);
90 linePrefixList=cell(size(lineStrList));
91 linePrefixList{1}=elemNumStr;
92 if numel(linePrefixList)>1
93 linePrefixList{2:end}=blankStubStr;
95 lineStrList=strcat(linePrefixList,lineStrList);
97 listOflineStrList{iHigherDimElem}=lineStrList;
100 lineStrList=vertcat(listOflineStrList{:});
105 linePrefix=sprintf(
'%s=\n',varName);
106 lineStrList=vertcat(linePrefix,lineStrList);
109 fprintf(
'%s\n',lineStrList{:});
115 function lineStrList=
showCellInternal(inpCMat,nSpaces,fNumPrint,fCharPrint,fCellPrint,isAsExpression,nMaxShownArrayElems)
117 isCellVec=cellfun(
'isclass',inpCVec,
'cell');
118 isLogicalVec=cellfun(
'isclass',inpCVec,
'logical');
119 isCharVec=cellfun(
'isclass',inpCVec,
'char');
120 [~,isNumericVec]=
mxberry.
core.iscellnumeric(inpCVec);
123 isSpecialEmptyVec=isCharVec|isCellVec|isNumericVec;
124 isEmptyVec=cellfun(
'isempty',inpCVec)&...
125 (cellfun(@(x)any(size(x)>0),inpCVec)&isSpecialEmptyVec|...
128 isEmptyVec=
false(size(inpCVec));
131 isLessElemVec=cellfun(@(x)(numel(x)<=nMaxShownArrayElems),inpCVec);
132 isExprNumVec=(isNumericVec|isLogicalVec)&isLessElemVec&~isEmptyVec;
134 isCharVec=isCharVec&isLessElemVec&~isEmptyVec;
135 isCellVec=isCellVec&isLessElemVec&~isEmptyVec;
137 isOtherVec=~(isEmptyVec|isExprNumVec|isCharVec|isCellVec);
139 %% Deal with empty elements
140 inpCVec(isEmptyVec)=cellfun(@
getEmptyStr,inpCVec(isEmptyVec),...
141 'UniformOutput',
false);
143 %% Deal with cell elements
144 inpCVec(isCellVec)=cellfun(fCellPrint,inpCVec(isCellVec),...
145 'UniformOutput',
false);
146 %% Deal with numeric elements
147 inpCVec(isExprNumVec)=cellfun(fNumPrint,...
148 inpCVec(isExprNumVec),
'UniformOutput',
false);
149 %% Deal with
string elements
150 % Put single quotes around the strings
151 inpCVec(isCharVec)=cellfun(fCharPrint,inpCVec(isCharVec),...
152 'UniformOutput',
false);
153 %% Deal with elements other than
string or numeric
154 % --------------------------------------------------------------------------
155 indOtherVec=find(isOtherVec);
156 nOtherElems=numel(indOtherVec);
158 for iObj=1:nOtherElems
159 indOther=indOtherVec(iObj);
160 valueObj=inpCVec{indOther};
161 valSizeVec=size(valueObj);
162 valNDims=ndims(valueObj);
163 className=
class(valueObj);
165 %% Display size and
class information
167 isEnum=isenum(valueObj);
168 isScalar=isscalar(valueObj);
170 inpCVec{indOther}=sprintf(
'%s',
char(valueObj));
172 highDimFormat=
'%d-D %s';
173 lowDimFormat=
'%dx%d %s';
176 inpCVec{indOther}=sprintf(lowDimFormat,valSizeVec(1),...
177 valSizeVec(2),className);
179 inpCVec{indOther}=sprintf(highDimFormat,valNDims,className);
183 %% Reconstruct the original size
184 inpCMat=reshape(inpCVec,size(inpCMat));
185 %% Transform a cell array of strings into a cell vector of line strings
187 lineStrList={
mxberry.
core.
cell.cellstr2expression(inpCMat,
false,
true)};
190 'minSepCount',nSpaces,
'UniformOutput',
false);
195 valSizeVec=size(inpVal);
196 valNDims=ndims(inpVal);
197 className=
class(inpVal);
199 %% Display size and
class information
201 isEnum=isenum(inpVal);
202 isScalar=isscalar(inpVal);
204 resStr=sprintf(
'%s',
char(inpVal));
206 highDimFormat=
'%d-D %s';
207 lowDimFormat=
'%dx%d %s';
210 resStr=sprintf(lowDimFormat,valSizeVec(1),...
211 valSizeVec(2),className);
213 resStr=sprintf(highDimFormat,valNDims,className);
216 function resStr=
numArr2str(inpVal,~,isClassShown,varargin)
217 origSizeVec=size(inpVal);
218 if max(origSizeVec)==0
220 resStr=[
class(inpVal),
'([])'];
226 inpArgList={
'class'};
230 isReshaped=~ismatrix(inpVal);
234 resStr=mat2str(inpVal,varargin{:},inpArgList{:});
236 resStr=[
'reshape(',resStr,
',',mat2str(origSizeVec),
')'];
240 origSizeVec=size(inpVal);
241 if max(origSizeVec)==0
244 isReshaped=~
isrow(inpVal);
249 inpVal=['''',strrep(inpVal,
'''',''''''),
'''']; 251 inpVal=['reshape(
',inpVal,',
',mat2str(origSizeVec),')
']; 255 inpVal=other2str(inpVal); 257 inpVal=['''',inpVal,
'''']; 263 function resStr=getEmptyStr(x) 265 resStr=[class(x),'.empty(
',sprintf('%d,
',sizeVec(1:end-1)),... 266 sprintf('%d
',sizeVec(end)),')
']; function other2str(in inpVal)
function throwerror(in msgTag, in varargin)
THROWERROR works similarly to built-in ERROR function in case when there is no output arguments but s...
function repmat(in inpArray, in varargin)
function showcell(in inpCArr, in varargin)
SHOWCELL generates a string representation of cell array or displays it in a console.
function charArr2str(in inpVal, in isAsExpression)
function showCellInternal(in inpCMat, in nSpaces, in fNumPrint, in fCharPrint, in fCellPrint, in isAsExpression, in nMaxShownArrayElems)
function numArr2str(in inpVal, in ignoredArg, in isClassShown, in varargin)
function getEmptyStr(in x)
function isrow(in inpArray)