When looking at nested for loops like yours, the first question I always ask is why are you using a for loop to begin with? To address this question, we can look at some of your innermost for loops:
for i3=1:3
a3 = A(i3)
for i2=1:3
a2 = A(i2)
for i1=1:3
a1 = A(a1)(i1)
end
end
end
Now we can step through this in our heads and realize the following: 1) a3 is not used in a2 or a1. a2 is not used in a1 2) A little closer inspection will tell us because of this independence in their relationship, not only are the for loops unnecessary, they are in fact pointless
The following code will produce the same results as this innermost nested for loop structure:
a3 = A(3);
a2 = A(3);
a1 would simply give you an error as you are trying to say that
a1 = A(a1)(3)
which does not make sense in MATLAB.
