How to use set_param(BlockX, 'SampleTime') during runtime of Simulink?
4 ビュー (過去 30 日間)
古いコメントを表示
Dear Community,
i know the topic of how to use set_param() to change params of chosen Simulink Blocks is well discussed, but I couldn't get an answer to this:
As the pictures show, I got a sin(x) signal, doing 3 periods wth a certain frequency before i got another iteration with higher frequency and so on. This goes from 0.1mHz to 1kHz and I want to have 600 samples per period. Meaning that I want to change the sample time of the "Signal Editor" Block everytime I go to a higher frequency. Therefore I want the sample time to be 1/(SamplesPerPeriod*CurrentFrequency).
The counter and the matlab-fcn only get relevant when the frequency jumps to the higher value and tries to update the sample time by:
set_param('SineTest/Signal Editor','SampleTime',SampleTime_new);
But it says that it 'cannot change parameter 'Sample Time' of Signal Editor while simulation is running' How do i solve this? Is there a way that i can change it during runtime or tell Simulink to pause, change it and resume?
Thanks for your help in advance :)
Best wishes
0 件のコメント
採用された回答
Harald
2023 年 6 月 23 日
Hi FJ,
as the error message indicates, I don't think this can be done directly.
My recommendation would be to choose the sample time in a way that all the desired sample times are multiples of that sample time.
An alternative might be a for-loop with sim commands, capturing the final state of the model and using that as initial state (e.g., for integrators or unit delays) for the next run.
Best wishes,
Harald
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Iterator Subsystems についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!