How to store a matrix from a loop?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
James Taylor
il 11 Feb 2016
Commentato: Star Strider
il 11 Feb 2016
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 Commenti
Risposta accettata
Star Strider
il 11 Feb 2016
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 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!