I need a substitute for the eval function in Simulink?

6 ビュー (過去 30 日間)
Robert Brown
Robert Brown 2021 年 11 月 4 日
回答済み: prabhat kumar sharma 2024 年 7 月 2 日
I have a program in simulink and need to set/chage a number of variable values while executing. I found this can easily do this in Matlab using the eval function, but can't find something similar on the Simulink side. One need-to-know is the executable is running on a remote machine.
Example of it working in Matlab:
Say variable foo = 1, I can send a UDP message with the string "foo=2", and process that string with eval function, now foo=2.
I've also tried assignin(), but it too is "not supported for code generation"
Any help would be appreciated.
  3 件のコメント
Robert Brown
Robert Brown 2023 年 3 月 14 日
I never recieved any feedback, this would be a super useful routine. We had to just predetermine all the variables we would want to change and create unique messages for each, super annoying.
Stefan Andrei
Stefan Andrei 2023 年 3 月 14 日
Alright, thank you for the quick response.

サインインしてコメントする。

回答 (1 件)

prabhat kumar sharma
prabhat kumar sharma 2024 年 7 月 2 日
Hi Robert,
I understand that you want parameter tuning in Simulink similar to MATLAB's eval(). Here are two methods that might be useful:
Method 1: Using Simulink Real Time Explorer
You can use Simulink Real-Time Explorer to change parameters in your real-time application while it is running or between runs. This method does not require rebuilding the Simulink model or setting it to external mode.
https://www.mathworks.com/help/slrealtime/ug/tune-parameters-with-xpc-target-explorer.html
Method 2: Tune Parameters by using simulink external mode.
Here are the steps you can follow:
  • Use external mode in Simulink to allow real-time parameter tuning.
  • Define the parameters you want to change as tunable parameters.
  • Use set_param to change the values of these parameters dynamically while the model is running.
  • Set up a communication mechanism (e.g., UDP) to receive commands and execute them using set_param.
You Can refer this docuemntation for further reference:
I hope it helps!

カテゴリ

Help Center および File ExchangeProgrammatic Model Editing についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by