First cell in array is empty

4 visualizzazioni (ultimi 30 giorni)
Angelina Cha
Angelina Cha il 4 Dic 2019
Modificato: Adam Danz il 6 Dic 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

Risposta accettata

Adam Danz
Adam Danz il 4 Dic 2019
Modificato: Adam Danz il 6 Dic 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

Più risposte (0)

Categorie

Scopri di più su Elementary Polygons in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by