How to use inputs from GUI in a separate script?

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 Kommentare

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.
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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Rik
Rik am 21 Mär. 2020

0 Stimmen

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 Kommentare

Tony Sadaka
Tony Sadaka am 21 Mär. 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 am 21 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 21 Mär. 2020

Kommentiert:

Rik
am 21 Mär. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by