How to store a matrix from a loop?

1 回表示 (過去 30 日間)
James Taylor
James Taylor 2016 年 2 月 11 日
コメント済み: Star Strider 2016 年 2 月 11 日
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 Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by