MATLAB: Matlab GUI – Pushbutton internal IF condition semi-not functional

buttonguiif statementmatlab gui

Hey Experts,
I got a problem with a GUI I am designing. I am writing some IF-ELSE IF statements inside the button as a check-condition for different increments. The relevant code can be found below.
function Simulate_Callback(hObject, eventdata, handles)
DP = str2double(get(handles.dummy, 'String'));
if (DP/handles.testdata.actualDP)*100 >=60
down =1;
elseif (DPrice/handles.testdata.actualDP)*100 < 60 && ...
(DPrice/handles.testdata.actualDP)*100 > 50
down = 0.5;
else
down = 0.05;
end
newString = sprintf('%d', int32(DP -down));
set(handles.dummy,'String',newString)
Initial value of DP is 100 and while is going down to 59 as it was supposed to (down=1), It looks like that handles.dummy does not update after that point and is stack on 59.
Any ideas guys? I can't get my mind around it.
Thanks a lot for your help! 🙂

Best Answer

You used int32(DP -down) . int32() rounds fractional values, so if DP is an integral value, DP-0.05 or DP-0.5 is going to round to DP.
What are you expecting to have happen when you decrement by a fraction and force the result to be integer?
Related Question