MATLAB: How compare the current true value with previous true value

loop and if

hello…i have used loop and if ..my problem is i want subtract the previous true value of if from current true value of if also >>>anybody can help me i will be regard

Best Answer

lasttruevalue = inf;
for K = 1 : 50
newvalue = somefunction(K);
if newvalue > 3
thistruevalue = newvalue;
truedifference = thistruevalue - lasttruevalue;
disp(truedifference);
lasttruevalue = thistruevalue;
end
end