MATLAB: Difference between two iteration of for loop

for loopiterationMATLAB

Hi I need to have difference between to successive iteration of for loop. As example:
For i=1:n P(i)=statement; end
How can I calculate: DeltaP=P(i)-P(i-1)??!! THANKS

Best Answer

diff( P )
after the for loop should do this for you for all pairs of consecutive elements of P