Creating a GUI based calculator

1 view (last 30 days)
Gregory
Gregory on 24 Jun 2014
Edited: Joseph Cheng on 24 Jun 2014
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 Comments
Geoff Hayes
Geoff Hayes on 24 Jun 2014
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 on 24 Jun 2014
Awesome, thank you so much for the help.

Sign in to comment.

Accepted Answer

Joseph Cheng
Joseph Cheng on 24 Jun 2014
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 Comments
Gregory
Gregory on 24 Jun 2014
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 on 24 Jun 2014
Edited: Joseph Cheng on 24 Jun 2014
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)

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!