Create GUI from existing code

103 visualizzazioni (ultimi 30 giorni)
Jamie Skovron
Jamie Skovron il 10 Mar 2016
Risposto: Ahmet Cecen il 10 Mar 2016
Hey guys, I have an existing code that requires 4 inputs (two material selections and 2 material thicknesses) to run. I have created an independent GUI that has push buttons for the material options and a write-in text box for the thickness value. What is the easiest way to have the GUI take the selected values and send those to the original code? But I would also need the existing code to output the output values back to the GUI for display purposes? For example: The user would select the push button called "Al6063" and the GUI would send to the original code that M1=6063. Any help would be appreciated...Thanks!

Risposte (1)

Ahmet Cecen
Ahmet Cecen il 10 Mar 2016
1) Convert your code into a function.
2) Create a GUI element for every input to your function. I would use "GUIDE".
3) When you open the script corresponding to the GUI, most elements should tell you how to access the input, something like:
get(hObject,'Value')
and assign that to a global variable:
global param1
param1 = get(hObject,'Value');
4) Create a RUN button on the GUI. Go to the buttons script and add something like:
global param1
global param2
global param3
global result
result = myfunction(param1,param2,param3);
5) Create an element to display your result, then set the value for it, with something like:
global result
set(hObject,'Value',result)
There is a way to not use any global variables to do this, but since you are asking this question, I am assuming you want an answer you can understand, rather than an answer that is neat.

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by