Help me about the Edit text GUIDE ?

2 次查看(过去 30 天)
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.

采纳的回答

Jan
Jan 2013-12-22
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 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by