How to set the initial value for iteration in Simulink?
44 次查看(过去 30 天)
显示 更早的评论
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
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
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/234182/Screenshot%20from%202019-08-16%2011-56-03.png)
And then the iteration will work.
0 个评论
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!