Help me about the Edit text GUIDE ?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Nguyen Trong Nhan
el 22 de Dic. de 2013
Respondida: Jan
el 22 de Dic. de 2013
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 comentarios
Respuesta aceptada
Jan
el 22 de Dic. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!