Hello,
you could use Simulink.Bus.createObject and create a Bus object of the bus that is sent to workspace, for example like:
Simulink.Bus.createObject(gcs,[gcs '/Bus Creator1'],'somefilename');
In this, gcs is your current system and the path to your Bus Creator has to be adapted. This will create Bus objects in the Base Workspace for the chosen bus and also the bus signals included. I wrote a function, that loops through this and just displays the included signals and their dimensions. It also checks the base workspace for the existence of the temporary BusElement. If yes, it might be a bus itself, if not, it is most likely a signal. Before you run the script, you will also need the Base Workspace variables saved in a cell, which could be achieved by this:
BWS_vars = who;
for i=1:length(BWS_vars)
BWS_vars{i,2} = eval(BWS_vars{i,1});
end
But note: If there are busses and signals within your model that have the same name, the script would cause an infinite loop. In order to avoid that, I included a timer and the script will stop after 2 seconds. Here is the function, call it with the BusObject that contains the signal you want to log as array and with the base workspace cell:
function getSignalNamesAndDimensions(BusObject,BWS_vars,timer)
if nargin<3
timer = tic;
end
if toc(timer) > 2
error('Possible infinite loop!');
end
n_Elements = length(BusObject.Elements);
for ind = 1:n_Elements
element_temp = BusObject.Elements(ind);
if any(strcmp(BWS_vars(:,1),element_temp.Name))
busCheck = BWS_vars(strcmp(BWS_vars(:,1),element_temp.Name)==1,2);
if isa(busCheck{1},'Simulink.Bus')
getSignalNamesAndDimensions(busCheck{1},BWS_vars,timer);
end
else
fprintf([element_temp.Name '\t' num2str(element_temp.Dimensions) '\n']);
end
end
end
I hope this might help you.
Kind regards, Stefan