Using a structure for "Variable name" in "To Workspace" block in Simulink

Is there a way to get the To workspace block in simulink to save data in to a structure variable. For example, in one subsystem of my whole model I would like to log data in to the variable name "engine1.speed" and in another subsystem i would like to use "engine2.speed" and "engine2.voltage".
Is this possible?
Thank you in advance!

 Accepted Answer

You can export Simulink outputs into MATLAB sturcts with "To Workspace" (see here for details) but they would not look like what you want. I believe the easiest workaround is to use MATLAB function by exempting the "assignin" for compiling with "coder.extrinsic".
See the attached file for detailed implementation.

More Answers (0)

Products

Release

R2021b

Community Treasure Hunt

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

Start Hunting!