Creating a GUI based calculator

조회 수: 1 (최근 30일)
Gregory
Gregory 2014년 6월 24일
편집: Joseph Cheng 2014년 6월 24일
I am trying to create a GUI based calculator, in it I use drop boxes and buttons to assign values to certain input parameters. Using these parameters I need to perform calculations that will be displayed in a static text box within the GUI. What I am having trouble with is displaying the results into static text boxes. I know I should be able to use a set command to do this but it is not working. Any ideas? I can show you my code if you are curious but didn't want to muddle the question up with code.
  댓글 수: 8
Geoff Hayes
Geoff Hayes 2014년 6월 24일
I'm using the handle to the control, handles.editTextField, to set its string value to num2str(days). In GUIDE, the handles structure contains a list of (among other things) the handles to all widgets (text boxes, popup menus, sliders, axes, etc.)
My example may illustrate a difference between using GUIDE and you yourself writing the GUI code. Check out Joseph's solution below which, while similar, will work for your case.
Gregory
Gregory 2014년 6월 24일
Awesome, thank you so much for the help.

댓글을 달려면 로그인하십시오.

채택된 답변

Joseph Cheng
Joseph Cheng 2014년 6월 24일
Most-likely you are not setting the return calculations as strings when setting them to the static text.
set(handles.statictexttag,'String',num2str(2));
  댓글 수: 9
Gregory
Gregory 2014년 6월 24일
I got it to work I think. But one or two more questions, if you would be so kind. I want to pull 'days' into a function that would calculate other values. Can I do that using a global variable or will that not change as the GUI is changed, is there a better way to do that? I also want to return other values calculated in the function that does actual calculations. Can I do that straight from there or do I need to use another callback function?
Joseph Cheng
Joseph Cheng 2014년 6월 24일
편집: Joseph Cheng 2014년 6월 24일
I would get out of using global variables. I would suggest using the guidata() function http://www.mathworks.com/help/matlab/ref/guidata.html which you store your variables in the guidata. if you look at the section for calling it within a function (using myhandles = guidata(gcbo)) you can then store values as myhandles.days and save it with guidata(gcbo,myhandles). This way you can call it from different functions without having to figure out how to pass it.
So using this method you can store anything you want under the structure myhandle (or anything else you want to call it)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by