How to split Simulink.S​imulationO​utput into its constituent entities

13 views (last 30 days)
Hello,
I am using a variable named ‘simout’ of type Simulink.SimulationOutput which captures all the output variables (using To Workspace block in Simulink to bring back into base workspace) after running the Simulink model. I would like to split the simout into its separate constituent signals, so that I can assign them individually from the dropdown menu of the MATLAB App Designer and plot them in the App Designer’s pane. Please suggest me the possible ways to implement this.
Thank you!

Answers (1)

Aabha
Aabha on 11 Feb 2025 at 7:43
Edited: Aabha on 12 Feb 2025 at 3:29
From what I understand, you want to obtain separate signals from a Simulink simulation output object, which has been generated using the “To Workspace” block. Then you want to add a dropdown menu in the App Designer, which allows you to select these signals and then plot the selected signal.
In order to do this, you can try the following steps:
After running the simulation, you can extract individual signals from the simout object using the get method or dot notation. The signals are in the “timeseries” format by default, so you will have to extract the data and time vectors separately for plotting. Here is an example of the code to help you with this:
signal1 = simout.get('signal1Name');
time1 = signal1.time;
data1 = signal1.data;
You can also use the “who” function to obtain the names of all simulation output variables, including workspace variables, as follows:
simoutVars = simout.who;
Once you have split the “simout” object into its constituent signals, you can create a dropdown menu from the “Component Library” in the App Designer. This dropdown can be populated based on the extracted signals. In order to achieve this, click on the “app.DropDown” option in the component browser. In the dialog titled “Items”, type the names of the desired signals.
To plot these signals in the App Designer pane, first add an “Axes” component from the Component Library.
Next, use a callback function for the dropdown menu. In the “Code View” of the App Designer, modify the callback function to plot the values of the signal selected in the dropdown. Here is an example code to help you with this:
function dropDownValueChanged(app, event)
selectedSignal = app.SignalDropdown.Value;
switch selectedSignal
case 'signal1Name'
plot(app.UIAxes, time1, data1);
case 'signal2Name'
% Similarly plot other signals
end
end
This callback function should plot whichever signal is selected from the dropdown menu, and it will be called whenever the selected signal is changed.

Community Treasure Hunt

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

Start Hunting!