I have been trying to get this persistent variable to work and I'm not sure what is wrong. The idea is that I enter a value i.e. 'annualbalance(2000)'. If the value is less than £5000 the interest will be 5% and if its greater than or equal to £5000 then the interest will be 10%. I want to be able to run the function manually as many times as I like until I get a value above, let's say £5100 hence why I have not used a loop.
function annualbalance(x)
persistent annualbalance;
if isempty(annualbalance)
annualbalance = 0;
elseif annualbalance < 5000
annualbalance = annualbalance * 1.05
elseif annualbalance >= 5000
annualbalance = annualbalance * 1.10
end
annualbalance(2000)which returns 2100. What do you do for the next year? Callannualbalance(2000)again? Callannualbalance(2100)? Not sure what you want. - Daniel