MATLAB: Increment different rates in same for-loop

for loopMATLABmatlab function

You value of k is [0,1,1,….]. While running the loop, it will throw this error,
Subscript indices must either be
real positive integers or logicals.
,for sure because you are using M3(k,1) later in the program, which never be possible in case of k=0;

Best Answer

I've solved the issue using this format:
iter = [1 2 3 4 5 6 7 8; 1 1 2 2 3 3 4 4; 1 1 1 1 2 2 2 2];
for i = 1:8
j = iter(1,i)
k = iter(2,i)
l = iter(3,i)
M4(i) = M1(j,1) * M2(k,1) * M3(l,1)
end