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

4 次查看(过去 30 天)
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.

回答(1 个)

stozaki
stozaki 2020-9-19
编辑:stozaki 2020-9-20
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.
set_param(gcbh,'A',num2str(X(1,1)))
set_param(gcbh,'B',num2str(X(1,2)))
set_param(gcbh,'C',num2str(X(2,1)))
set_param(gcbh,'D',num2str(X(2,2)))
or
X = [1 2;3 4]
set_param(gcbh,...
'A',num2str(X(1,1)),...
'B',num2str(X(1,2)),...
'C',num2str(X(2,1)),...
'D',num2str(X(2,2)))
Regards,
stozaki
  1 个评论
Walter Roberson
Walter Roberson 2020-9-20
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Modeling 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by