I want to add previous matrixes in for loop
Show older comments
here is my code
x = [pi/4 pi/6 0];
Ex = 181 *10^9;
Ey = 10.3 *10^9;
Es = 7.17 *10^9;
Vx =0.28;
Vy = (Ey/Ex)*Vx;
M1 = (1/(1-(Vx*Vy)));
Qxx = M1*Ex;
Qyy = M1*Ey;
Qxy = M1*Vy*Ex;
Qyx = M1*Vx* Ey;
Qss = Es;
asd = [];
for i = 1:length(x)
m = cos(x(i));
n = sin(x(i));
h2 = input("h2 = ")
h1 = input("h1 = ")
sh = [m^4 n^4 (2*m^2*n^2) (4*m^2*n^2);
n^4 m^4 (2*m^2*n^2) (4*m^2*n^2);
(m^2*n^2) (m^2*n^2) (m^4+n^4) (-4*m^2*n^2);
(m^2*n^2) (m^2*n^2) (-2*m^2*n^2) (m^2-n^2)^2;
(m^3*n) ( -m*n^3) (m*n^3 - m^3*n) 2*(m*n^3-m^3*n);
(m*n^3) (-m^3*n) (m^3*n - m*n^3) 2*(m^3*n - m*n^3)
];
matrixQ =[Qxx ;Qyy ;Qxy ;Qss];
c = sh * matrixQ;
QMatrix = [c(1) c(3) c(5); c(3) c(2) c(6);c(5) c(6) c(4)];
QT = QMatrix
%QTOTAl = QT + QT(i:9)
end
I do not know how can i add output matrixes of for loop
1 Comment
Walter Roberson
on 1 Jan 2023
You appear to be calculating a 3 x 3 matrix at each step.
%QTOTAl = QT + QT(i:9)
suggests that the first time, you want the full 9 elements to be part of the running sum, but the second time you want the last 8 (linear indexing) elements only, and the third time you want the last 7 (linear indexing) elements only, and so on. It is not clear whether you are trying to calculate
out(1,1) = first QT(1) + second QT(1) + third QT(1) ... last QT(1)
out(2,1) = second QT(2) + third QT(2) ... last QT(2)
out(3,1) = third QT(1) ... last QT(1)
or if you are wanting to output a series of 3 x 3 arrays ... or something else ?
Perhaps you should record all of the QT results, and arrange them along the third dimension, and then do a cumsum() along the reverse of the third dimension ??
QT3 = cat(3, QT_CELL{:});
sum3 = flip(cumsum( flip(QT3, 3) ), 3)
Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!