MATLAB: Using for loops to check elements

checkelementsforloops

I have vector a=[1 2 4 4 2 1] and I want to create a for loop that does some calculations between each element of a, i.e. it performs the calculations between 1 and 2, then between 2 and 4, then between 4 and 4, 4 and 2, then 2 and 1. How can I do this? Thanks.

Best Answer

for i=1:length(a)-1
interval = a([i i+1]);
dosomething(interval);
end
Related Question