First cell in array is empty

3 vues (au cours des 30 derniers jours)
Angelina Cha
Angelina Cha le 4 Déc 2019
Modifié(e) : Adam Danz le 6 Déc 2019
Why is my first cell array empty in my variable a_th?
I should be getting:
[.02*(10^-6);
22.5*(10^-6);
0]
Instead I am getting an empty cell [ ].
I am running this program on R2017a.
%% thermal expansion
% Givens
theta = [0,90];
theta = theta*(pi/180);
a1 = 0.02*(10^-6);
a2 = 22.5*(10^-6);
a12 = 0;
delT = -75;
% Transformation Matrix
for i = 1:length(theta)
m = cos(theta(i)); %angle [rad]
n = sin(theta(i)); %angle [rad]
T{i} = [m^2, n^2, 2*m*n;
n^2, m^2, -2*m*n;
-m*n, m*n, (m^2)-(n^2)];
end
% Thermal expansion and Thermal strains for all angles of ply
for i = length(theta)
a_th{i} = T{i}*[a1;a2;a12];
ex = a_th{i}(1)*delT; %ax*deltaT
ey = a_th{i}(2)*delT; %ay*deltaT
exy = a_th{i}(3)*delT; %axy*deltaT
e_th{i} = [ex;ey;exy];
end

Réponse acceptée

Adam Danz
Adam Danz le 4 Déc 2019
Modifié(e) : Adam Danz le 6 Déc 2019
oops! Typo...
should be
for i = 1:length(theta)
% ^^
end
Two more unrelated tips:
  1. Always pre-allocate your loop variables (shown below)
  2. numel() is safer than length()
a_th = cell(size(theta)); % PRE-ALLOCATE
e_th = cell(size(theta)); % PRE-ALLOCATE
for i = 1:numel(theta) % USE NUMEL
. . .
end

Plus de réponses (0)

Catégories

En savoir plus sur Elementary Polygons dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by