Creating a GUI based calculator
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Gregory
il 24 Giu 2014
Modificato: Joseph Cheng
il 24 Giu 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 Commenti
Geoff Hayes
il 24 Giu 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.
Risposta accettata
Joseph Cheng
il 24 Giu 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 Commenti
Joseph Cheng
il 24 Giu 2014
Modificato: Joseph Cheng
il 24 Giu 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)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!