MATLAB Answers

How to run a matlab function using a button pushed in AppDesigner

7 views (last 30 days)
Hello everyone,
My question is simple. I want to run a function in matlab base workspace using a button pushed in AppDesigner.
I added a button in my app, and create a callback with this instruction :
run ('Path of my function');
My function is (just for the test) :
function r=addition(a,b)
Thank you in advance.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 19 Jul 2021
Edited: Matt J on 19 Jul 2021
The typical way would be to invoke addition() from your callback the way you would from any ordinary function,
function ExecuterButtonPushed(app,event)
Matt J
Matt J on 21 Jul 2021
Maybe it will be more clearly with this explanations.
I'm afraid not. What you have not explained is why the machine you are controlling needs to receive its instructions from a Matlab script as opposed to an mfunction. As Jan points out, you could easily convert your script to a function and invoke that function directly from the callback, as my original answer suggests.
Also, even if you insist on using a script, it is not clear what problems you are currently experiencing by running your script from the callback. I can only guess it is because there are additional variables that the script needs besides the EditField values and which reside in the base workspace. If so, why not just bring those extra variables into the app where the callback can see them? Make them inputs to the app constructor and store them in properties.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by