NaN error when trying to display calculation result

4 views (last 30 days)
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 :)

Accepted Answer

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH on 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);

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!