How to use inputs from GUI in a separate script?

21 vues (au cours des 30 derniers jours)
Tony Sadaka
Tony Sadaka le 21 Mar 2020
Commenté : Rik le 21 Mar 2020
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 commentaires
Carlos Molina
Carlos Molina le 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.
Tony Sadaka
Tony Sadaka le 21 Mar 2020
so if i want to take the input from a texbox(named Z) in guide, i type in the script(named composite):
composite(Z);
and for the output(named X) from the script to guide i type in the callback:
function composite(X)
text=X.statictext.string;
end
?????????????
im sorry im still a beginner in guide. i looked up alot of tutorials but didnt help much

Connectez-vous pour commenter.

Réponses (1)

Rik
Rik le 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 commentaires
Tony Sadaka
Tony Sadaka le 21 Mar 2020
[a,b,c,d,e]=deal(in.a,in.b,in.c,in.d,in.e);
in.a,in.b and so on are my inputs(handles.input) from guide converted to a,b,c in the script?
and
[out.a,out.b,out.c,out.d,out.e]=deal(a,b,c,d,e);
and here a,b,c,d,e are outputs from script converted to guide outputs out.a,out.b,out.c?
sorry but as i said im beginner at guide :P
Rik
Rik le 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by