How to store a matrix from a loop?
1 次查看(过去 30 天)
显示 更早的评论
I want to be able to store the matrices that are produced from the for loop.
% Clearing EVERYTHING
clear all
close all
clc
% Declaring variables
E1 = 170;
E2 = 12;
G12 = 4.5;
v12 = 0.3;
vf = 0.6;
%Calculation
Z = (E1-((v12^2)*E2))/E1;
Q11= E1/Z;
Q22 = E2/Z;
Q12 = (v12*E2)/Z;
Q66 = G12;
Q_matrix = [Q11 Q12 0;
Q12 Q22 0;
0 0 Q66];
for angle = (-45:45:90)*pi/180;
m = cos(angle);
n = sin(angle);
Stress_matrix_1 =[m^2 n^2 -2*m*n;
n^2 m^2 2*m*n;
m*n -m*n m^2-n^2];
Strain_matrix_1 = [m^2 n^2 -m*n;
n^2 m^2 m*n;
2*m*n -2*m*n m^2-n^2];
Q_bar = (Stress_matrix_1)*(Q_matrix)*inv(Strain_matrix_1)
end
0 个评论
采纳的回答
Star Strider
2016-2-11
I would save them as cell arrays:
anglev = (-45:45:90)*pi/180; % Angle Vector
for k1 = 1:length(anglev)
angle = anglev(k1); % Angle
m = cos(angle);
n = sin(angle);
Stress_matrix_1{k1} =[m^2 n^2 -2*m*n;
n^2 m^2 2*m*n;
m*n -m*n m^2-n^2];
Strain_matrix_1{k1} = [m^2 n^2 -m*n;
n^2 m^2 m*n;
2*m*n -2*m*n m^2-n^2];
Q_bar{k1} = (Stress_matrix_1)*(Q_matrix)*inv(Strain_matrix_1)
end
Also, if you want to use degrees, you can avoid the conversion to radians in your code, and use the cosd and sind functions. In my experience, they’re more accurate for degree arguments than doing the conversion in your code.
2 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numbers and Precision 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!