How to store a matrix from a loop?

1 visualización (últimos 30 días)
James Taylor
James Taylor el 11 de Feb. de 2016
Comentada: Star Strider el 11 de Feb. de 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

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Numbers and Precision en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by