Create GUI from existing code

조회 수: 14 (최근 30일)
Jamie Skovron
Jamie Skovron 2016년 3월 10일
답변: Ahmet Cecen 2016년 3월 10일
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!

답변 (1개)

Ahmet Cecen
Ahmet Cecen 2016년 3월 10일
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.

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by