Skip to content
Snippets Groups Projects
Commit 3481f1fb authored by Federico Felici's avatar Federico Felici
Browse files

Cleanup and add support for recursive buses

parent 41989c09
No related branches found
No related tags found
No related merge requests found
......@@ -5,27 +5,32 @@
% and with zero data of the correct kind
% This is enough for passing a ctrl-D with from Workspace bus kind blocks
function [out] = SCDconf_createsimdatastruct(bus)
function [out] = SCDconf_createsimdatastruct(dd,busname)
bus=dd.getEntry(busname).getValue; % get from data dictionary
bussize=size(bus.Elements);
signalssize=bussize(1);
tempstruct=struct();
for ii=1:signalssize
elementdim=bus.Elements(ii).Dimensions;
switch numel(elementdim)
case 1,
data=zeros(elementdim(1),2)';
case 2,
data=zeros(elementdim(1),elementdim(2),2);
otherwise,
error('Not supported data structure');
end
tscmd=sprintf('tmpts=timeseries(%s(data),[0;1]);',bus.Elements(ii).DataType);
eval(tscmd);
structcmd=sprintf('tempstruct.%s=tmpts;',bus.Elements(ii).Name);
eval(structcmd);
element=bus.Elements(ii);
if contains(element.DataType,'Bus: ')
busname = erase(element.DataType,'Bus: ');
% recursive call
out.(element.Name) = SCDconf_createsimdatastruct(dd,busname);
else
try cast(1,element.DataType); catch ME; error('non-numeric type'); end
elementdims=element.Dimensions;
switch numel(elementdims)
case 1
data=zeros(elementdims(1),2)';
case 2
data=zeros(elementdims(1),elementdims(2),2);
otherwise
error('Not supported data structure');
end
out.(element.Name) = ...
timeseries(cast(data,element.DataType),[0;1],'Name',element.Name);
end
end
out=tempstruct;
%out=Simulink.SimulationData.createStructOfTimeseries(bus,tempstruct)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment