# MATLAB: Creating dynamic variables using loops | Automatic Variables using loops

base matrixdynamic variablesevaleyefor looploopsmatricesmatrixzeros

Hello,
I believe that I am in a predicament. I have already read that trying to create variables from a loop (using eval like A1, A2, … ) is not advisable and its better to initialize empty matrices using zeros. But I think that I have to breach this. Please advise on alternative options if you know any.
Here's the trouble.
So I need to be creating a cyclic matrix. I will create a base matrix where each element is an identity matrix shifted right by that element. For example I have created a base matrix –
Ha =     1     2     4     8    16     5    10    20     9    18    25    19     7    14    28
Now each element is actually supposed to be an identity matrix. All identity matrices's size are 31×31.
So Ha(1,1) is identity matrix of size 31×31 (hereafter referred as eye(31))
Ha (1,2) is eye(31) cyclically shifted right by 2
Ha (1,3) is eye(31) cyclically shifted right by 4
Ha (2,3) is eye(31) cyclically shifted right by 20
And so on…..
I believe that I must be creating variables like A1, A2, A4,…. to as many as I have in Ha.
How do I bypass this without creating variables using loops.
If it helps, the final matrix size is row*31 by col*31 = 3*31, 5*31
Size of Final Matrix = 93, 155

Ha = [1     2     4     8    16; ...     5    10    20     9    18; ...    25    19     7    14    28];HaC = cell(size(Ha));Ha(1, 1) = 0;  % Not 1Data = eye(31);for k = 1:numel(HaC)    HaC{k} = circshift(Data, -Ha(k), 1);endM = cell2mat(HaC);
M    = nan([31, 31, size(Ha)]);Ha(1, 1) = 0;  % Not 1Data = eye(31);for i3 = 1:size(Ha, 1)    for i4 = 1:size(Ha, 2)       M(:, :, i3, i4) = circshift(Data, -Ha(i3, i4), 1);    endendM = reshape(permute(M, [1,3,2,4]), 31 * size(Ha))