Retrieve values from edit box in GUI and assign them to a variable

3 Ansichten (letzte 30 Tage)
Ann Clay
Ann Clay am 18 Apr. 2015
Beantwortet: Image Analyst am 18 Apr. 2015
I am a student still learning about Matlab, and I can't find any information that is basic enough for me to understand about using editable boxes in a GUI to retrieve an input value and assign it to a variable. I can get it to retrieve info when the return key is pressed, but cannot get it to assign this info to a variable.
Here is my code thus far:
f=figure('Color', [.2 .5 .3], 'Position',[200,200,900,600])
inputBox = uicontrol('Style','edit','Position',[70 520 150 30])
set(inputBox, 'keypressfcn', {@Keypress});
switch E.Key case 'return' pause(.01) year = get(inputBox, 'string') str2num('year') S = get(editBoxHandle, 'string'); otherwise end
At the moment, when I input a value into the editable text box, the command window prints
year =
34 (34 being whatever value is input)
but the workspace shows nothing about the variable year, so apparently it has not been assigned a value.
Many thanks in advance
AC

Antworten (2)

Star Strider
Star Strider am 18 Apr. 2015
This may be the problem:
str2num('year')
See if:
year = str2num(year);
improves things.

Image Analyst
Image Analyst am 18 Apr. 2015
I really suggest you take a look at this framework. http://www.mathworks.com/matlabcentral/fileexchange/24224-magic-matlab-generic-imaging-component It does all that for you - gets variables from GUI widgets and puts them into program variables for all the types of widgets available (edit fields, checkboxes, etc.).
Description
This GUI will help the novice user get up to speed very quickly on using GUI-based applications. Everything is laid out in a very simple Step 1, Step 2, Step 3, etc. layout. It is a very good starting point for a typical image analysis application. This application uses GUIDE to do the user interface design, and has most of the basic controls such as buttons, listboxes, checkboxes, radio buttons, scrollbars, etc. It allows the user to ..............

Kategorien

Mehr zu App Building finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by