Looping and storing variable to be used in Simulink model
5 views (last 30 days)
Show older comments
I have a set of omegas and k, which is being used to calculate d. I am then using the each w and d value in a Simulink transfer function to create a plot (simulink model shown below). I don't know if this is possible, but instead of manually changing k, w, and d each time to then run in the Simulink model, is it possible to use a loop function in Matlab to find each value of d and w at the given k and store that so that you can apply each to the Simulink model? I also put the data I am working with below to help clarify.
Please let me know if you need clarification or my question doesn't make sense.
(My attempt at the code so far):



0 Comments
Answers (1)
ag
on 22 Apr 2025
Hi Ashlynn,
To automate the mentioned process using a loop in MATLAB to calculate the values of "d" and "w" for each "k" you can use the MATLAB function "sim".
The below code snippet demonstrates how to achieve the same:
% Rest of the code
% Loop start
% Set parameters for the Simulink model
simin = Simulink.SimulationInput('your_model_name');
simin = simin.setVariable('k', k);
simin = simin.setVariable('w', w);
simin = simin.setVariable('d', d);
% Run the Simulink model
simOut = sim(simin);
% Loop end
For more details, please refer to the following MathWorks documentation:
Hope this helps!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!