I have a question. As i am using a MATLAB function block. I cannot use recursive functions like for loop and while loop. Therefore, I need to replace my code using If function. I have a code which has an for loop within a while loop function as shown below. How to i convert it to If function or is there other ways to not use recursive function?
while abs((max(Pnew)-min(Pnew))/max(Pnew))>0.05 for i = 1:4 f = 0.3 + (0.5-0.3)*B; vnew(i) = vold(i)+(DPold(i) - DPbest)*f; if DPold(i) > DPbest(i) DPnew(i) = DPold(i) - abs(vnew(i)); else DPnew(i) = DPold(i) + abs(vnew(i)); end if rand(0,1)>rold(i) DPnew(i) = DPold(i) + mean(Aold)*e; end D = DPnew(i); Pnew(i) = P; if Pnew(i) < Pold(i) DPnew(i) = DPold(i); Pnew(i) = Pold(i); end Anew(i) = 0.5*Aold(i); rnew(i) = rold(i)*(1-exp(-0.5)); endendDPbest = max(DPnew);D = DPbest;
Best Answer