|
17 | 17 | % rootname: the name of the root-object, when set to '', the root name |
18 | 18 | % is ignored, however, when opt.ForceRootName is set to 1 (see below), |
19 | 19 | % the MATLAB variable name will be used as the root name. |
20 | | -% obj: a MATLAB object (array, cell, cell array, struct, struct array) |
| 20 | +% obj: a MATLAB object (array, cell, cell array, struct, struct array, |
| 21 | +% class instance) |
21 | 22 | % filename: a string for the file name to save the output UBJSON data |
22 | 23 | % opt: a struct for additional options, ignore to use default values. |
23 | 24 | % opt can have the following fields (first in [.|.] is the default) |
|
129 | 130 | txt=struct2ubjson(name,item,level,varargin{:}); |
130 | 131 | elseif(ischar(item)) |
131 | 132 | txt=str2ubjson(name,item,level,varargin{:}); |
| 133 | +elseif(isobject(item)) |
| 134 | + txt=matlabobject2ubjson(name,item,level,varargin{:}); |
132 | 135 | else |
133 | 136 | txt=mat2ubjson(name,item,level,varargin{:}); |
134 | 137 | end |
|
328 | 331 | end |
329 | 332 | txt=[txt,'}']; |
330 | 333 |
|
| 334 | +%%------------------------------------------------------------------------- |
| 335 | +function txt=matlabobject2ubjson(name,item,level,varargin) |
| 336 | +if numel(item) == 0 %empty object |
| 337 | + st = struct(); |
| 338 | +else |
| 339 | + % "st = struct(item);" would produce an inmutable warning, because it |
| 340 | + % make the protected and private properties visible. Instead we get the |
| 341 | + % visible properties |
| 342 | + propertynames = properties(item); |
| 343 | + for p = 1:numel(propertynames) |
| 344 | + for o = numel(item):-1:1 % aray of objects |
| 345 | + st(o).(propertynames{p}) = item(o).(propertynames{p}); |
| 346 | + end |
| 347 | + end |
| 348 | +end |
| 349 | +txt=struct2ubjson(name,st,level,varargin{:}); |
| 350 | + |
331 | 351 | %%------------------------------------------------------------------------- |
332 | 352 | function txt=matdata2ubjson(mat,level,varargin) |
333 | 353 | if(isempty(mat)) |
|
0 commit comments