Driving data from GUI application to the matlab script

1 view (last 30 days)
Shyam Vudata
Shyam Vudata on 18 Nov 2021
Answered: Yongjian Feng on 18 Nov 2021
I am building a GUI application using App Designer. A button on the GUI invokes .m script(through callback) that has certain variables hard-coded and are used for the
execution of the script. These are the same variables I would want to drive through GUI(edit number field) to let the user decide the values and see the impact in results.
Let's say X is a variable within .m script and I want to change it through GUI. Tried this:
In .m script:
-------------
Before X is defined, added below line
app = app1; (app1 is the name of my GUI Application)
X = app.y; (where y is defined as a public property with no default values assigned in the GUI application)
In GUI application:
------------------
properties (Access = public)
y
end
function buttonPushed(app,event)
app.y = app.X_EditField.Value; (X_EditField is created as an entry using the Edit Field(Numeric) from Component Library)
run ('<.m>')
end
What am I doing wrong?

Answers (1)

Yongjian Feng
Yongjian Feng on 18 Nov 2021
Why don't you create your matlab script as a function and then take y as an input argument?
function foo(y):
% whatever your script needs to do with y
end
Put this function in the same location of your app or in a folder of matlab path, then in your app you can just call it
foo(y);

Community Treasure Hunt

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

Start Hunting!