changing a parameter inside a continuous transfer function during simulation
조회 수: 3 (최근 30일)
이전 댓글 표시
Hey guys, I want to change a parameter of a continuous transfer function during a simulation. Is that possible?
댓글 수: 0
답변 (1개)
Sebastian Castro
2015년 8월 17일
Yes, it is possible.
You can go right into the block and change the parameters mid-simulation. When you hit "OK" in the block, the parameters update.
If you want to do this programmatically, you can do the following -- suppose you are changing a parameter K in a model called myModel:
>> K = 0.2;
>> set_param('myModel','SimulationCommand','update');
- Sebastian
댓글 수: 2
Sebastian Castro
2015년 8월 17일
I just tried this out by putting the above MATLAB commands inside a MATLAB Function block. Notice a few subtle changes like declaring some functions extrinsic (due to code generation), and also assigning values in the MATLAB base workspace with assignin (a necessary "evil" in this case).
coder.extrinsic('assignin');
coder.extrinsic('set_param');
assignin('base','w0',5);
set_param('untitled','SimulationCommand','update');
This is then placed inside a Triggered Subsystem that triggers when the simulation time exceeds a certain value. For example:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/180487/image.jpeg)
Notice that I am changing the frequency w0 from 1 to 5 at a time of 4 seconds. My results change as follows:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/180489/image.jpeg)
- Sebastian
참고 항목
카테고리
Help Center 및 File Exchange에서 Schedule Model Components에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!