Skip to content
Snippets Groups Projects
Commit 1b450149 authored by Marco Luigi Gaibotti's avatar Marco Luigi Gaibotti Committed by Marco Luigi Gaibotti
Browse files

[to-struct-updates] Added support for vectorized classes

parent 9c9de5ba
Branches
No related tags found
1 merge request!27[to-struct-updates] Improved toStruct for classes
...@@ -62,21 +62,23 @@ classdef(Abstract) Config ...@@ -62,21 +62,23 @@ classdef(Abstract) Config
% This method is useful when the class is inteded to be read only % This method is useful when the class is inteded to be read only
% e.g. as a parameter for simulink models % e.g. as a parameter for simulink models
sz = size(obj);
structOut = struct(); structOut = struct();
structOut = repmat(structOut, sz);
fields = obj.getProperties('readable'); fields = obj.getProperties('readable');
if options.recursive
for j = 1:size(fields, 2) for j = 1:size(fields, 2)
field = obj.(fields{j}); field = {obj.(fields{j})}; % Concatenate to support obj arrays
if isa(field, 'Config')
field = field.toStruct();
end
structOut.(fields{j}) = field; % Check for type only on the first element: since the
end % input is an array of objects, all elements are
else % guaranteed to have the same type
for j = 1:size(fields, 2) if options.recursive && isa(field{1}, 'Config')
structOut.(fields{j}) = obj.(fields{j}); field = [field{:}]; % Convert to array for toStruct
field = num2cell(field.toStruct('recursive', true)); % Convert to cell for assignment
end end
[structOut.(fields{j})] = deal(field{:});
end end
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment