How to write To Workspace data to a workspace

3 views (last 30 days)
A
A on 27 Aug 2021
Answered: ag on 27 Dec 2024
I want to be able to run Simulink from a program, write To Workspace data to the workspace in real time, and use the workspace values in calculations within the program.
Please answer. It would be appreciated if you could include the programme.

Answers (1)

ag
ag on 27 Dec 2024
Hi A,
I understand that you want to run a Simulink model using a MATLAB script, with the objective of storing the simulation output in the MATLAB workspace and subsequently utilizing these values for further calculations.
To achieve this, you can employ the "To Workspace" block in Simulink, which allows you to write data directly to the MATLAB workspace.
Below is a self-explanatory script that demonstrates how you can execute the model from the script and use the output data for calculations:
% Define the Simulink model name
modelName = 'your_model_name';
% Simulate the model
out = sim(modelName);
% Extract the output from the "To Workspace" block
toWksData = out.simout;
% Perform calculations with the obtained data
calculatedData = 2 * toWksData;
For more details, please refer to the following MathWorks documentations:
Hope this helps!

Categories

Find more on Simulink in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!