Help me about the Edit text GUIDE ?
1 view (last 30 days)
Show older comments
For example I make a simple GUI to calculate the sum of 2 number. I make 1 button, 2 edit text(with tag: edit1 and edit2), 1 static text to display the result(with tag: sum1)
function SUM_Callback(hObject, eventdata, handles) a = str2double(get(handles.edit1,'string')); b = str2double(get(handles.edit2,'string')); s = a + b; set(handdles.sum1,'string',s);
I run the GUI. for example I type at the edit text 1 number 0.5 and at the edit text 2 number 0.6. Press the button, so it run normally and doesn't have error.the result is 1.1. OK But if I type in the edit text the fraction : 1/2 and 3/5. the result is NaN.it is not understand. Could you help me how to input the fraction in edit text of GUI that it can understand and the result still exactly. thanks you very much.
0 Comments
Accepted Answer
Jan
on 22 Dec 2013
As described in the documentation, str2double interprets the input string in a strict numerical format: see help str2double . There you find the hint, that str2num is more powerful and accepts expressions like "1/2" also.
Nevertheless, take into account that it evaluates even expressions like "!format C:", which would format your harddisk (if modern operating systems would not stop you from doing this...).
0 Comments
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!