MATLAB: Strange problem – vector dimensions

loop vector dimension

Hello, I am facing a weird problem and I do not know why. I have saved on my disk some .mat files called: SIMGAtheta1_0 SIMGAtheta2_0 … SIMGAtheta21_0
Then, I am trying to run the following code:
for kk=1:21;
disp(kk)
s = (['SIMGAtheta', num2str(kk), '_', num2str(q)]);
load(s)
A(kk) = ... calculations.... ;
clear SIMGA*
end
That is, I want it to upload each SIMGA… file in turn, perform some calculations, save those as the next (kk-th) element of the vector A and again… 21 times. The problem is that when kk=7, it puts the new calculation as a first element in the vector (!). So it messes up the whole thing. And I do not see why this is going on, and why at the 7th loop. Note that if I break the latter into two, it works. I.e. if I do the following I get what I want:
for kk=1:6;
disp(kk)
s = (['SIMGAtheta', num2str(kk), '_', num2str(q)]);
load(s)
A1(kk) = ... calculations...;
clear SIMGA*
end
for kk=7:21;
disp(kk)
s = (['SIMGAtheta', num2str(kk), '_', num2str(q)]);
load(s)
A2 = ....calculations....;
clear SIMGA*
end
A = [A1 A2];
But I do not understand why it does not work doing it in "one go". Thanks for any help/suggestion.
Kyriacos
[EDITED, Jan Simon, code formatted]

Best Answer

My guess is that there is a variable called 'A' in your 7th m-file. What if you call your array AAA (to avoid naming conflicts) instead, does this fix it immediately?
This would also explain why your second example works, with variables called A1 and A2.