Create GUI from existing code

14 visualizaciones (últimos 30 días)
Jamie Skovron
Jamie Skovron el 10 de Mzo. de 2016
Respondida: Ahmet Cecen el 10 de Mzo. de 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!

Respuestas (1)

Ahmet Cecen
Ahmet Cecen el 10 de Mzo. de 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.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by