Hi there, I have the following five matrices:
A1 = ones(5,5)*1;
A2 = ones(5,5)*2;
A3 = ones(5,5)*3;
A4 = ones(5,5)*4;
A5 = ones(5,5)*5;
I want a total of 96 seperate matrices and want to repeat A1,A2,A3,A4 and A5 after every 32 loops, Hence, I will have at the end 96 of 5 x 5 matrices consiting of A1, A2, A3, A4 and A5. So, the first 6 matrices (1-6) are of A1, the second lot of (7-12) matrices are A2, the third lot (13-18) are A3, the fouth (19 – 24) are A4 and A5 (25 – 32). After the 32nd matrix I want to go back to A1 and repeat as before till we get 96 matrices.
So, I have attempted the code below:
for i = 1:96
for j = 1:3
for k = 1:32
U(:,:,k,j) = A1;
Ux(:,:,i) = U(:,:,k,j);
if k > 6
U(:,:,k,j) = A2;
Ux(:,:,i) = U(:,:,k,j);
end
if k > 12
U(:,:,k,j) = A3;
Ux(:,:,i) = U(:,:,k,j);
end
if k > 18
U(:,:,k,j) = A4;
Ux(:,:,i) = U(:,:,k,j);
end
if k > 24
U(:,:,k,j) = A5;
Ux(:,:,i) = U(:,:,k,j);
end
end
end
end
Could someone help me acheive this please?
Many thanks in advance, guys!
,,Hi there, I have the following five matrices:
A1 = ones(5,5)*1;
A2 = ones(5,5)*2;
A3 = ones(5,5)*3;
A4 = ones(5,5)*4;
A5 = ones(5,5)*5;
I want a total of 96 seperate matrices and want to repeat A1,A2,A3,A4 and A5 after every 32 loops, Hence, I will have at the end 96 of 5 x 5 matrices consiting of A1, A2, A3, A4 and A5. So, the first 6 matrices (1-6) are of A1, the second lot of (7-12) matrices are A2, the third lot (13-18) are A3, the fouth (19 – 24) are A4 and A5 (25 – 32). After the 32nd matrix I want to go back to A1 and repeat as before till we get 96 matrices.
So, I have attempted the code below:
for i = 1:96
for j = 1:3
for k = 1:32
U(:,:,k,j) = A1;
Ux(:,:,i) = U(:,:,k,j);
if k > 6
U(:,:,k,j) = A2;
Ux(:,:,i) = U(:,:,k,j);
end
if k > 12
U(:,:,k,j) = A3;
Ux(:,:,i) = U(:,:,k,j);
end
if k > 18
U(:,:,k,j) = A4;
Ux(:,:,i) = U(:,:,k,j);
end
if k > 24
U(:,:,k,j) = A5;
Ux(:,:,i) = U(:,:,k,j);
end
end
end
end
Could someone help me acheive this please?
Many thanks in advance, guys!
,, Hi there, I have the following five matrices:
A1 = ones(5,5)*1;
A2 = ones(5,5)*2;
A3 = ones(5,5)*3;
A4 = ones(5,5)*4;
A5 = ones(5,5)*5;
I want a total of 96 seperate matrices and want to repeat A1,A2,A3,A4 and A5 after every 32 loops, Hence, I will have at the end 96 of 5 x 5 matrices consiting of A1, A2, A3, A4 and A5. So, the first 6 matrices (1-6) are of A1, the second lot of (7-12) matrices are A2, the third lot (13-18) are A3, the fouth (19 – 24) are A4 and A5 (25 – 32). After the 32nd matrix I want to go back to A1 and repeat as before till we get 96 matrices.
So, I have attempted the code below:
for i = 1:96
for j = 1:3
for k = 1:32
U(:,:,k,j) = A1;
Ux(:,:,i) = U(:,:,k,j);
if k > 6
U(:,:,k,j) = A2;
Ux(:,:,i) = U(:,:,k,j);
end
if k > 12
U(:,:,k,j) = A3;
Ux(:,:,i) = U(:,:,k,j);
end
if k > 18
U(:,:,k,j) = A4;
Ux(:,:,i) = U(:,:,k,j);
end
if k > 24
U(:,:,k,j) = A5;
Ux(:,:,i) = U(:,:,k,j);
end
end
end
end
Could someone help me acheive this please?
Many thanks in advance, guys!
,, for loop, matrix, matrices MATLAB Answers — New Questions
