How to use inputs from GUI in a separate script?
12 views (last 30 days)
Show older comments
I have written a 300 line script that performs all the anaylsis and calculations for matrices and plots, given user inputs. To get those inputs from the user and display the results and plots, i have created a GUI. My question is, how do i take the inputs from the GUI i made, plug them into the script, run the script and take the outputs from the script and plug them back into the GUI. ( I have aloooot of inputs and outputs )
The GUI is already set with proper tags. i just dont know how to link the GUI with the script.
Please provide example if u can of ur answer since i am learning GUI as i go and i am a beginner.
Your help is Extremely appreciated, i need this for a project in my university.
Note: My script is not a function
2 Comments
Carlos Molina
on 21 Mar 2020
Dear Tony
You can pass from gui to your script function the object or value that you get there, and from the script function you can access to the propierties of the object in the GUI.
For example, if you have in app designer (if you are in GUIDE use the equivalent) a drop-down object, and you want to give access to the script for reading or modificating a property of the object, pass the object from the guide to the function.
read(app.dropdown);
and then in your script called read
function read(obj)
text = obj.Value;
end
Or from the GUI
read(app);
and from the script
function read(app)
text = app.dropdown.Value;
end
So, in resume, if you pass the app itself, or the object directly, you can access to the propierty and modificate them from the script without problems.
Answers (1)
Rik
on 21 Mar 2020
This is trivial if you convert your script into a function. With complex functions with many inputs and outputs it would often make sense to store both in a struct.
function out=complexFunction(in)
%syntax desciption goes here
%deal the inputs
[a,b,c,d,e]=deal(in.a,in.b,in.c,in.d,in.e);
%do calculations
%gather the outputs
out=struct;
[out.a,out.b,out.c,out.d,out.e]=deal(a,b,c,d,e);
end
2 Comments
Rik
on 21 Mar 2020
You can ignore the example if it doesn't help you. My point is that your script should be a function. That way you have inputs and outputs. Inside your GUI you can call that custum function, just like you would call a function like max or sort. Your callback function needs to gather all relevant values, call the function, and store the results to where-ever you need them.
If you need more help with GUI design: https://www.mathworks.com/matlabcentral/answers/483657-how-to-create-a-gui
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!