MATLAB: Iterate over vector from result of a for loop

loop over vector

I have a vector capacity and I want to iterate over this vector in such a way that that in every iteration 480 is subtracted from the resulted vector for example capacity=[750 350 950 650 600 500 450 700 850 950]
loop 1=capacity-480
result=[270 -130 470 170 120 20 -30 220 370 470]
loop 2=result-480
result={-210 -610 -10 -310 -360 -460 -510 -260 -110 -10]
and so on..meanwhile save every result vector I tried different techniques but cant sort out the desired result e.g
for i=1:3
result(i)=capacity(i)-480
final=[result(i);result(i+1)]
end
but I cant understand how to do this.Any expert can help me out in this please?

Best Answer

This is MATLAB so there is no need to rely on low-level loops. For MATLAB versions R2016b and later:
capacity - 480*(1:5).'
or for older versions:
bsxfun(@minus,capacity,480*(1:5).')