How to set the initial value for iteration in Simulink?

조회 수: 38 (최근 30일)
Sisi Di
Sisi Di 2016년 8월 31일
답변: Yichen Hu 2019년 8월 16일
I'm building a model in Simulink on iteration algorithm, but I failed to set the inital value for my parameters. I used a 'Matlab Function' block to write in my codes. I tried to initial them in the file, but they would be reset to the initial value when the block is called in the Simulink. Also, the different delay for each parameter bother me a lot when I tried to figure out the prority of the blocks.Thanks a lot.
  댓글 수: 1
Martin
Martin 2016년 9월 7일
Hello, I did little while ago something similiar, the variable you can initialize directly in code like this:
function untitled()
persistent b
if isempty(b)
b = 25; % Initial value
end
b = b + 1;
disp(b)

댓글을 달려면 로그인하십시오.

답변 (2개)

Yichen Hu
Yichen Hu 2019년 8월 16일
I have also faced with this problem days ago, and I have come up with this idea:
Connect a delay block to the output of the Fuction block, and set the initial condition of the delay block to the initial value you want.
Screenshot from 2019-08-16 11-56-03.png
And then the iteration will work.

Naushin Shaikh
Naushin Shaikh 2016년 9월 15일
You can try defining its default value in model explorer. So, whenever the variable will be called it will take the default value. To reset its value, you can then add its reset value in code.

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by