Effacer les filtres
Effacer les filtres

Help me about the Edit text GUIDE ?

2 vues (au cours des 30 derniers jours)
Nguyen Trong Nhan
Nguyen Trong Nhan le 22 Déc 2013
Réponse apportée : Jan le 22 Déc 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.

Réponse acceptée

Jan
Jan le 22 Déc 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...).

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by