MATLAB: For loop for variables

for loop

I have written one code as follows,
for i=1:10
Ai=i;
fprintf('A is: %d \n',Ai)
end
what i want to achieve from here is, I want to store 1,2,3..10 in variables A1,A2,A3…A10. But the code i have created is giving me Ai as variable instead A1,A2…etc and storing Ai=10 at the end.(It has also created row vector A=[1:10])

Best Answer

@Stephen: Haha I read the same thing somewhere online. But that didn't stop me :3
for i=1:10
eval(sprintf('A%i = i',i))
end
Related Question