Exporting multidimensional signals from the Simulation Data Inspector programmatically

1 view (last 30 days)
I have a simulation for which I log several signals and among them there are some with a size greater than 1.
In the Simulation Data Inspector the signals are grouped according to the Data Hierarchy and this allows me to see the multidimensional signals grouped together but with the opportunity to read each individual "channel". (Settable from the gear in the upper right of the Run window under "Group" in the "Then by" field but also from scripts as shown below.)
My goal is to handle all the signals from scripts, which is why I wrote the following script (MATLAB 2019a):
Simulink.sdi.setTableGrouping('DataHierarchy'); % if you open the sdi GUI you can see that the command is apllied
runIDs = Simulink.sdi.getAllRunIDs;
runID = runIDs(end); % Get last Run
run = Simulink.sdi.getRun(runID);
for i = 1:run.SignalCount
signal = getSignalByIndex(run,i);
signal_name_1 = signal.Name
end
SignalIDs = run.getSignalIDsByName('MultiDimSig')
for i = 1:length(a)
signal_name_2 = run.getSignal(SignalIDs(i)).Name
end
Given a multidimnsional signal logged with the name 'MultiDimSig' with dimension N the above script print:
signal_name_1 = MultiDimSig(1,1)
signal_name_1 = MultiDimSig(1,2)
.
.
.
signal_name_1 = MultiDimSig(1,N)
signal_name_2 = MultiDimSig
signal_name_2 = MultiDimSig(1,1)
signal_name_2 = MultiDimSig(1,2)
.
.
.
signal_name_2 = MultiDimSig(1,N)
Ultimately the problem I encounter is that by loopping with the index I do not find the MultiDimSig multidimensional signal but only its 'channels' whereas by doing a name search and taking the handle of the signal from the ID it is possible to directly take the handle of the multidimensional signal.
This seems to suggest that run.SignalCount is less than the number of IDs available in the run

Answers (1)

Githin George
Githin George on 12 Dec 2023
Hello Pasquale,
It is my understanding you are trying to obtain the signals from Simulink Data Inspector by looping over the “SignalCount” and using the method “getSignalIDsByName” and noticing an inconsistency as the 2nd method is giving an extra value for output.
I have run a model containing multi-dimensional signals in R2019a and noticed that the extra output obtained on executing run.getSignalIDsByName('MultiDimSig') is the parent signal.
I have also run the model in Simulink R2020a and observed that run.getSignalIDsByName('MultiDimSig') command only returns the parent Signal. But the returned parent Signal has an additional property “Children”(See properties for “Simulink.sdi.signal” class) which contains the original signals.
I am attaching the Simulink R2020a documentation link for “Simulink.sdi.signal” class and “getSignalIDsByName” function which explains how the various signals can be accessed from Simulink Data Inspector.
For more consistency, I suggest you update your MATLAB version to R2020a or higher.
I hope this helps.

Categories

Find more on Audio Processing Algorithm Design in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!