How can i update my simulink variable from m file in each iteration

3 views (last 30 days)
i define my state space model in matlab simulink. The matrix for the state space model is defined in m.file. The values of matrix elements can vary in each iteration. How can i update matrix elements defined in m file and used in simulink. I don't want to use these matrix elements as function output.

Answers (1)

stozaki on 19 Sep 2020
Edited: stozaki on 20 Sep 2020
Hello Kousalya,
If you use the Discrete State-Space block, set it as follows:
% Definition of matrix elements
X = [1 2;3 4]
% Discrete State-Set the defined value to the Space parameter
% "gcbh" is the handle of the block selected with the mouse.
% Highlight the Discrete State-Space block with the mouse before running.
% Alternatively, enter the block path name.
X = [1 2;3 4]
  1 Comment
Walter Roberson
Walter Roberson on 20 Sep 2020
You would have had to use sim() with parameters that cause it to perform only one iteration. But what is an "iteration" for your purposes? One time step? I would think it would be very inefficient to run only one timestep per sim() call.

Sign in to comment.


Find more on Programmatic Model Editing in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!