- Always pre-allocate your loop variables (shown below)
- numel() is safer than length()
First cell in array is empty
4 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Adam Danz
on 4 Dec 2019
Edited: Adam Danz
on 6 Dec 2019
oops! Typo...
should be
for i = 1:length(theta)
% ^^
end
Two more unrelated tips:
a_th = cell(size(theta)); % PRE-ALLOCATE
e_th = cell(size(theta)); % PRE-ALLOCATE
for i = 1:numel(theta) % USE NUMEL
. . .
end
0 Comments
More Answers (0)
See Also
Categories
Find more on Elementary Polygons in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!