extracting string from uicontrol edit text gui upon callback without using another function

1 view (last 30 days)
So here is my code:
rQ = uicontrol('Style','text',...
'String','How many rules are needed?',...
'Position',[10 350 200 15]);
rN = uicontrol('Style','edit',...
'Position',[10 300 200 15],...
'Callback','happy=1',...
'String','');
ruleNum = str2double(get(rN,'String'))
When I run this current code, my GUI shows the static text and the edit textbox with nothing in it and in the command window it shows "ruleNum=NaN". When I do type a number in and press enter, it just shows "happy=1". What I want is for ruleNum to equal the number I type into the edit textbox and I want this to occur after I have typed in the number and pressed enter. I can't call another function like http://www.mathworks.com.au/matlabcentral/answers/51337-how-to-evaluate-calback-function-in-edit-text-uicontrol because my code is part of an IF statement.
Thanks in advance
  2 Comments
Michael Haderlein
Michael Haderlein on 16 Aug 2014
Actually, you have to call another function like shown in the link. Also, there's a further link to Matt's tutorial on guis which might be helpful for you.
What do you mean with "my code is part of an IF statement"? I don't think there's a case in which you cannot to this. You just need to figure out how to do it.
Timothy
Timothy on 17 Aug 2014
Oh! I was under the assumption that I had to put the new function inside my current function. So I've added another function to the end of my current function and it works, thanks Michael! The code that I have posted is nested in an IF statement, that's what I meant.

Sign in to comment.

Answers (0)

Categories

Find more on Migrate GUIDE Apps 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!