MATLAB: NaN error when trying to display calculation result

MATLABnan

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 🙂

Best Answer

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);