21 error(
" The obj argument has to be a matlab object. ");
26 elseif ~isnumeric(maxdepth) || ~isreal(maxdepth)
27 error(
" maxdepth has to be a real value/integer. ");
29 sizelbl = [
" G ",
" M ",
" k ",
" b "];
30 [str, bytes] = recursive2str(obj, maxdepth, 0, []);
32 function [str, bytes] = recursive2str(obj, depth, numtabs, done)
41 if isfield(obj,
" Name ")
47 str = [str
" %s: " name
" \n "];
49 str = [name
" %s:\n "];
52 names = cellfun(@(mp)mp.Name,mc.Properties,
" UniformOutput ",
false);
53 [~, sortedidx] = sort(names);
54 bytes = 0; subbytes = 0;
55 for n = 1:length(sortedidx)
57 p = mc.Properties[idx];
59 if strcmp(p.GetAccess,
" public ")
60 str = [str repmat(
" \t ",1,numtabs)
" . "];
63 if ~isempty(pobj) && ~any(cellfun(@(el)isequal(pobj,el),done))
68 [recstr, addbytes] = recursive2str(pobj, depth-1, numtabs+1, done);
69 subbytes = subbytes + addbytes;
70 str = [str p.Name
" - " recstr];
71 elseif isnumeric(pobj)
73 sizestr = getSizeStr(addbytes);
75 sizestr = [
" ( " sizestr
" ) "];
81 str = [str p.Name
" : [ " num2str(size(pobj))
" ] " spar
class(pobj) sizestr];
83 pobj = reshape(pobj,1,[]);
84 str = [str p.Name
" : " num2str(pobj)];
87 if any(size(pobj) > 1)
88 str = [str p.Name
" (struct, [ " num2str(size(pobj))
" ]), fields: "];
90 str = [str p.Name
" (struct), fields: "];
92 fn = fieldnames(pobj);
93 for fnidx = 1:length(fn)
94 str = [str fn[fnidx]
" , "];
97 elseif isa(pobj,
" function_handle ")
98 str = [str p.Name
" (f-handle): " func2str(pobj)];
100 str = [str p.Name
" : " pobj];
101 elseif islogical(pobj)
103 str = [str p.Name
" : true "];
105 str = [str p.Name
" : false "];
108 str = [str sprintf(
" %s: %dx%d cell<%s> ", p.Name, size(pobj,1),size(pobj,2),
class(pobj[1]))];
110 str = [str p.Name
" : ATTENTION. Display for type ' " class(pobj)
" ' not implemented yet. "];
114 str = [str p.Name
" : [self-reference] "];
116 str = [str p.Name
" : empty "];
121 bytes = bytes + addbytes;
132 sizestr = sprintf(
" (self:%s, childs:%s, total:%s) ",...
133 getSizeStr(bytes-subbytes),getSizeStr(subbytes),getSizeStr(bytes));
135 sizestr = sprintf(
" (%s) ",getSizeStr(bytes));
137 str = sprintf(str,sizestr);
139 function res = getSizeStr(bytes)
140 hr = bytes ./ [1024^3 1024^2 1024 1];
141 pos = find(hr > 1,1);
144 res = sprintf(
" %.5g%s ",hr(pos),sizelbl[pos]);
Matlab's base handle class (documentation generation substitute)
function str = object2str(handle obj,integer maxdepth)
object2str: Generic matlab object to string converter.