First cell in array is empty

3 次查看(过去 30 天)
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

采纳的回答

Adam Danz
Adam Danz 2019-12-4
编辑:Adam Danz 2019-12-6
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Elementary Polygons 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by