Creating a GUI based calculator

3 次查看(过去 30 天)
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