How to use inputs from GUI in a separate script?

10 次查看(过去 30 天)
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 个评论
Carlos Molina
Carlos Molina 2020-3-21
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 2020-3-21
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

请先登录,再进行评论。

回答(1 个)

Rik
Rik 2020-3-21
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 个评论
Tony Sadaka
Tony Sadaka 2020-3-21
[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 2020-3-21
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by