How to tune variables during external mode?

조회 수: 4 (최근 30일)
Xiaojie Qiu
Xiaojie Qiu 2017년 11월 10일
댓글: Xiaojie Qiu 2017년 11월 13일
Hello everyone,
I want to determine which value a variable should be set for my motor control algrithm, so I try to tune the value of this variable with the help of Simulink external mode.
But during running, only such kind of variables are allowed to be tuned, when their values are explicitly displayed in the block.
For instance,
1) When the Constant value of the Constant block is set to 1. So it can be tuned during the mode.
2) When the Constant value of this block is set to C (my variable), however, it can not be tuned anymore.
Since there are many variables in the model, I don't find it's a wise way to replace all of them with their own values explicitly. So I tried to change its value in command window. Although according to the workspace a new value is assigned to the variable, but nothing changed in the Simulink model.
Is there anyone who can give me some advise?
Thank you!

채택된 답변

Birdman 2017년 11월 10일
You may create a mask from Constant block and in the mask, create a parameter named C which is your variable. Then in external mode, double click on the Constant block and enter your variable C on there. Try this.
  댓글 수: 1
Xiaojie Qiu
Xiaojie Qiu 2017년 11월 13일
Hello cvklpstunc,
Thank you very much! But I found a better way to tune parameters during external mode.
Method 1): In command window, assign a new value to the parameter that you want to tune and then click Simulation > Update Diagram (Ctrl + D) to let your simulink model evaluate its parameter value again.
Method 2): Programatically tuning parameters using a script. Fisrtly, all parameters to be tuned are defined in a script. Secondly, add this command set_param('ModelName', 'SimulationCommand', 'update') at the end of the script in order to update the diagram instead of doing it manually.
Please check the following documents for more information:
Best regards,
Xiaojie Qiu

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

추가 답변 (0개)


Community Treasure Hunt

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

Start Hunting!

Translated by