How to build a table within an if loop without preallocation
이전 댓글 표시
I'm having trouble building this table in my code. Currently it just displays the last value that was calculated rather than creating a table with all the values calculated. I have seen a lot of answers with for loops but none with if. Is there something I am missing? I even get the warning on T that it changes size every iteration, however, it doesn't seem to actually do that.
% Safety Factors
SFy = 1.25; % Yield
SFu = 1.50; % Ultimate
SFb = 2.0; % Stability
% ____ Material Properties
E = 31182; % (ksi) Modulus of Elasticity
Sy = 91.5; % (ksi) Yield Strength
Su = 112; % (ksi) Ultimate Strength
D = 0.25; % (in) Initial Outside Diameter Value
d = 0.001; % (in) Initial Inside Diameter Value
L = 36; % (in) Length of Bar
P = 3; % (ksi) Applied Axial Force
j = 1; % Book-keeping
while D <= 2 && d <= 0.249
I = pi*(D^4-d^4)/64; % (in^4) Moment of Inertia
Pcrt = (pi^2*E*I)/(L^2); % Calculating Pcr
SFbt = Pcrt/P;
if SFbt >= SFb
A = pi*(D^2-d^2)/4; % (in^2) Area Value
s = P/A; % (ksi) Axial Stress = Force/Area
SFyt = Sy/s; % Calculating Safety Factor Yield
SFut = Su/s; % Calculating Saftey Factor Ultimate
T = table(); % Storage Table
tempTable = table();
if SFyt >= SFy && SFut >= SFu % Checking for Validity
tempTable.D = D;
tempTable.d = d;
tempTable.A = A;
tempTable.s = s;
tempTable.Pcrt = Pcrt;
tempTable.SFut = SFut;
tempTable.SFyt = SFyt;
tempTable.SFbt = SFbt;
T = [T; tempTable];
end
end
if D >= 1.989 % Running Through Possibilities
d = d + 0.001;
D = 0.25;
end
D = D + 0.01;
j = j+1;
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Profile and Improve Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!