Azzera filtri
Azzera filtri

Help me about the Edit text GUIDE ?

2 visualizzazioni (ultimi 30 giorni)
Nguyen Trong Nhan
Nguyen Trong Nhan il 22 Dic 2013
Risposto: Jan il 22 Dic 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.

Risposta accettata

Jan
Jan il 22 Dic 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...).

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by