Azzera filtri
Azzera filtri

NaN error when trying to display calculation result

2 visualizzazioni (ultimi 30 giorni)
Hi,
When I try to run this code, the static text always says NaN?
I enter numbers for a, b and c. Then i try to do some calculations with these values and then try to display the answer "discriminant_string" in the static text box called Result_Text.
Why does it give me this result?
I'm using Matlab GUIDE for the GUI
Here is the code
a = get(handles.A_Value,'String');
b = get(handles.B_Value,'String');
c = get(handles.C_Value,'String');
p1 = str2double(b) * str2double(b);
p2 = str2double(a) * str2double(c) * 4;
discriminant = str2double(p1) * str2double(p2);
discriminant_string = num2str(discriminant);
set(handles.Result_Text,'String',discriminant_string);
Thank you very much, im just starting out :)

Risposta accettata

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH il 4 Nov 2019
solution:
a = get(handles.A_Value,'String');
b = get(handles.B_Value,'String');
c = get(handles.C_Value,'String');
p1 = str2double(b) * str2double(b);
p2 = str2double(a) * str2double(c) * 4;
discriminant = p1 * p2;
discriminant_string = num2str(discriminant);
set(handles.Result_Text,'String',discriminant_string);

Più risposte (0)

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by