Pay attention to the size of w2. It is a six-element array, not a seven element one. So your code should be:
for i=1:6
w2(i)=w(i)-w(i+1);
end
Alternatively, you can write:
w2=w(1:end-1)-w(2:end)
This avoids the time-consuming loop.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!