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

[to-struct-updates] Implemented type conversion for unsupported simulink types

parent b57c049c
No related branches found
No related tags found
1 merge request!27[to-struct-updates] Improved toStruct for classes
...@@ -9,6 +9,7 @@ classdef(Abstract) Structured ...@@ -9,6 +9,7 @@ classdef(Abstract) Structured
arguments arguments
obj obj
options.recursive (1, 1) logical = false options.recursive (1, 1) logical = false
options.convertData (1, 1) logical = true
end end
% toStruct - Standardizes struct conversion for Config classes % toStruct - Standardizes struct conversion for Config classes
% This function converts the object to a struct % This function converts the object to a struct
...@@ -19,6 +20,9 @@ classdef(Abstract) Structured ...@@ -19,6 +20,9 @@ classdef(Abstract) Structured
% Input Arguments % Input Arguments
% recursive - True to convert nested fields to struct % recursive - True to convert nested fields to struct
% false (default) | true % false (default) | true
% convertData - True to convert data to Simulink
% compatible format
% false (default) | true
% %
% NOTE: A struct does not posses update capabilities and only % NOTE: A struct does not posses update capabilities and only
% publicly readable fields are copied. % publicly readable fields are copied.
...@@ -37,13 +41,23 @@ classdef(Abstract) Structured ...@@ -37,13 +41,23 @@ classdef(Abstract) Structured
for j = 1:size(fields, 2) for j = 1:size(fields, 2)
% Concatenate in cell to handle nonscalar fields % Concatenate in cell to handle nonscalar fields
field = {obj.(fields{j})}; field = {obj.(fields{j})};
field = reshape(field, [], 1);
% Check for type only on the first element % Check for type only on the first element
if options.recursive && isa(field{1}, 'Structured') if options.recursive && isa(field{1}, 'Structured')
% Convert each element in cell to struct % Convert each element in cell to struct
field = cellfun(... for i=1:length(field)
@(f) f.toStruct('recursive', true), ... field{i} = field{i}.toStruct('recursive', true);
field, 'uniformOutput', false); end
end
if options.convertData
for i=1:length(field)
% Convert empty to NaN
if isempty(field{i}), field{i} = NaN; end
% Convert enums to strings
if isenum(field{i}), field{i} = string(field{i}); end
end
end end
[structOut.(fields{j})] = deal(field{:}); [structOut.(fields{j})] = deal(field{:});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment