MATLAB: Skipping if Statement even though a has been set to 0, on matlab GUI

if statement

Hi, My code skips this if statement when I set a to 0, why does this happen? It should go into the if statement and display a but it doesn't.
a = get(handles.A_Value,'String');
if a == 0
disp(a)
end
Thank you!

Best Answer

a = get(handles.A_Value,'String');
% a is a string, not a number.
% Option 1 is to convert a to a number
a = str2double(get(handles.A_Value,'String'));
if a == 0
disp(a)
end
% option 2 is to compare strings rather than numbers
a = get(handles.A_Value,'String');
if strcmp(a, '0')
disp(a)
end
% but be careful because what if user enters 0.0
% in that case '0' is different than '0.0'