MATLAB Answers

Call a Simulink Function from a Callback Button

15 views (last 30 days)
Thomas Kotwal
Thomas Kotwal on 28 Aug 2019
Commented: Thomas Kotwal on 3 Sep 2019
I have defined a Simulink Function in one subsystem with Function Visibility set to global. I verified this works by calling it from a Stateflow chart in a different subsystem.
I have a Callback Button dashboard control that I would like to use to call the Simulink Function. But when I run the simulation and click on the button, I get an error saying that the function doesn't exist. My guess is that it is possible, but I'm not calling it appropriately. The button is in the same subsystem as the Stateflow chart I used to call the Simuilnk Function.
The function is called txCommand(cmd).
In the Callback Button, I have the ClickFcn callback set to:
txCommand(51);
Is there particular syntax required to tell the Callback Button where to find the Simulink Function?
Thank you.

  0 Comments

Sign in to comment.

Answers (1)

Fangjun Jiang
Fangjun Jiang on 29 Aug 2019
I would think this is not possible. The callback function of the button needs to be MATLAB based. In other words, if the function can be called at the MATLAB Command line, then it can be called by the button callback. A Simulink function can not be called or executed at the MATLAB Command line.

  1 Comment

Thomas Kotwal
Thomas Kotwal on 3 Sep 2019
It's unfortunate that a Simulink function can not be called or executed programmatically from Matlab.
As a workaround, I ended up having the Callback Button modify the values of some Simulink Constant blocks, which trigger and set the inputs to a Simulink Function Caller block. It's certainly not as straightforward as calling the Simulink Function directly would be, but it gets the job done.
Thank you.

Sign in to comment.

Sign in to answer this question.

Products


Release

R2018b