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

采纳的回答

Star Strider
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 个评论
James Taylor
James Taylor 2016-2-11
Thank you very much for your help!!!
Star Strider
Star Strider 2016-2-11
My pleasure!
If my Answer solved your problem, please Accept it.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numbers and Precision 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by