Updating simulink block parameter as the simulation runs.

조회 수: 1 (최근 30일)
computer12345
computer12345 2020년 7월 6일
댓글: computer12345 2020년 7월 8일
Hello!
I'm new to Matlab and I'm wondering if this is possible.
I have a custom block with a mask that takes in 3 user-input parameters. One of the parameters is frequency and I want to vary the frequency with time while the simulation is running. I looked all over the internet and I found a suggestion to replace the frequency parameter with a workspace variable array, with the array setup as [time1 value1;time2 value2; time3 value3....]. I tried this, but I got an error saying that the there was an issue with the blocks in the subsystem reading the arrays properly. I placed this code into the InitFnc callback.
Am I doing going about this correctly? If so, what do I modify to ensure that the frequency input ports are correctly reading an array input?
If not, is there a different way I can go about changing the frequency with time? I am trying to do everything using a script, rather than including blocks like time steps since the block is masked.
Thanks!

채택된 답변

Fangjun Jiang
Fangjun Jiang 2020년 7월 7일
setting array value as [time1 value1;time2 value2; time3 value3....] works for signal, not for parameters. Use this approach instead
set_param(YourModel, 'SimulationCommand', 'pause');
set_param(YourBlock, parameter, value);
set_param(YourModel, 'SimulationCommand', 'continue');
  댓글 수: 5
Fangjun Jiang
Fangjun Jiang 2020년 7월 8일
It has nothing to do with other functions. The Assertion block is calling PauseFcn, so you have to have a .m script called PauseFcn.m in your MATLAB path.
computer12345
computer12345 2020년 7월 8일
ohhh I see. I thought that part could link straight to the callback functions associated with the model. Thanks for your help!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by