How to enter letters in edit?
1 view (last 30 days)
Show older comments
Good day. I have some variable 'a' which I enter in 'edit'-field. I need to enter letters(for example 'B') in that field,but when I do this and try to count something,MATLAB gives me a Callback error and in Workspace I can see that a have a value 'NaN'. What's wrong? And how can I fix it?
a=str2double(get(hI1,'string'))
and in another m.file:
hI1=uicontrol('Style','edit','Position',[220 400 200 30],'String','',...
'backgroundcolor',[0.1 0.1 0.1],'Fontsize',13,'foregroundcolor','w','parent',hW);
1 Comment
Answers (1)
Guillaume
on 22 May 2015
If you enter the letter 'B' in the edit box, then of course, trying to convert it to a number (with str2double) as you've done is not going to produce anything sensible. hence you get NaN (Not a Number).
To fix, don't convert to a number.
a = get(hI1, 'string'); %and use a better variable name than a
0 Comments
See Also
Categories
Find more on Characters and Strings 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!