MATLAB: Dynamic array storage with for loop

dynamic arrayfor loopMATLAB

D = 0.067;
Ugs = [0.047,0.061,0.288,0.344,0.404,0.544,0.709,0.945,1.418,1.891,2.363,2.836,4.727];
Uls = ones(1,13)*0.047;
Uls1 = ones(1,13)*0.071;
Uls2 = ones(1,13)*0.095;
Uls3 = ones(1,13)*0.142;
g = 9.81;
rho_gas=1.18;
rho_liq=900;
Ugs_aht= Ugs *((rho_gas).^0.5)/(g * D *(rho_liq - rho_gas)).^0.5;
Uls_aht= Uls *((rho_liq).^0.5)/(g * D *(rho_liq - rho_gas)).^0.5;
Uls1_aht= Uls1 *((rho_liq).^0.5)/(g * D *(rho_liq - rho_gas)).^0.5;
Uls2_aht= Uls2 *((rho_liq).^0.5)/(g * D *(rho_liq - rho_gas)).^0.5;
Uls3_aht= Uls3 *((rho_liq).^0.5)/(g * D *(rho_liq - rho_gas)).^0.5;
print(Uls_aht, Uls1_aht,Uls2_aht,Uls3_aht)
C = ((Ugs_aht).^0.5) + ((Uls_aht).^0.5);
C1 = ((Ugs_aht).^0.5) + ((Uls1_aht).^0.5);
C2 = ((Ugs_aht).^0.5) + ((Uls2_aht).^0.5);
C3 = ((Ugs_aht).^0.5) + ((Uls3_aht).^0.5);
flow = ones(1,13);
flow = string('flow');
for i = 1:13
if C <= 0.2(i)
flow(i)= 'Bubble'
if C1 <= 0.89(i)
flow(i)= 'Slug'
if C2 <= 0.98(i)
flow(i)= 'Transition'
if C3 >= 1.00(i)
flow(i)= 'Churn'
end
end
end
end
% end
Ugs = Ugs.';
Usl = Usl.';
Usl1 = Usl1.';
Usl2 = Usl2.';
Usl3 = Usl3.';
C = C.';
C1 = C1.';
C2 = C2.';
C3 = C3.';
Uls_aht = Uls_aht.';
Uls1_aht = Uls1_aht.';
Uls2_aht = Uls2_aht.';
Uls3_aht = Uls3_aht.';
% flow = flow.';
T = table(Ugs,Uls_aht,Uls1_aht,Uls2_aht,Uls3_aht,C,C1,C2,C3)

Best Answer

D = 0.067;% Diameter of tube in meters
Ugs = [0.047,0.061,0.288,0.344,0.404,0.544,0.709,0.945,1.418,1.891,2.363,2.836,4.727];
Uls = ones(1,13)*0.047;
Uls1 = ones(1,13)*0.071;
Uls2 = ones(1,13)*0.095;
Uls3 = ones(1,13)*0.142;
Uls4 = ones(1,13)*0.284;
Uls5 = ones(1,13)*0.378;
g = 9.81;% Acceleartion due to gravity (m/s^2)
rho_gas=1.18;% Gas density (Kg/m^3)
rho_liq=900;% Liquid density (Kg/m^3)
for i = 1:13
Ugs_aht(i)= Ugs(i) *((sqrt(rho_gas))/(sqrt(g * D *(rho_liq - rho_gas))));
end
Uls_aht= Uls *((sqrt(rho_liq))/(sqrt(g * D *(rho_liq - rho_gas))));
Uls_aht1= Uls1 *((sqrt(rho_liq))/(sqrt(g * D *(rho_liq - rho_gas))));
Uls_aht2 = Uls2 *((sqrt(rho_liq))/(sqrt(g * D *(rho_liq - rho_gas))));
Uls_aht3 = Uls3 *((sqrt(rho_liq))/(sqrt(g * D *(rho_liq - rho_gas))));
Uls_aht4 = Uls4 *((sqrt(rho_liq))/(sqrt(g * D *(rho_liq - rho_gas))));
Uls_aht5 = Uls5 *((sqrt(rho_liq))/(sqrt(g * D *(rho_liq - rho_gas))));
C = (sqrt(Ugs_aht)) + (sqrt(Uls_aht));
C1 = (sqrt(Ugs_aht)) + (sqrt(Uls_aht1));
C2 = (sqrt(Ugs_aht)) + (sqrt(Uls_aht2));
C3 = (sqrt(Ugs_aht)) + (sqrt(Uls_aht3));
C4 = (sqrt(Ugs_aht)) + (sqrt(Uls_aht4));
C5 = (sqrt(Ugs_aht)) + (sqrt(Uls_aht5));
Ugs =Ugs.';
Uls = Uls.';
Uls1 = Uls1.';
Uls2 = Uls2.';
Uls3 = Uls3.';
Uls4 = Uls4.';
Uls5 = Uls5.';
Ugs_aht = Ugs_aht.';
Uls_aht = Uls_aht.';
Uls_aht1 = Uls_aht1.';
Uls_aht2 = Uls_aht2.';
Uls_aht3 = Uls_aht3.';
Uls_aht4 = Uls_aht4.';
Uls_aht5 = Uls_aht5.';
C = C.';
C1 = C1.';
C2 = C2.';
C3 = C3.';
C4 = C4.';
C5 = C5.';
plot(C,Ugs_aht,'--r')
xlabel('C (sqrt(m/s))')
ylabel('Ugs_aht (m/s)')
title('Flooding Mechanism')
T= table(Ugs, Uls,Uls_aht, Ugs_aht, C,C1,C2,C3,C4,C5);
hold on
plot(C1,Ugs_aht,'--b')
hold on
plot(C2,Ugs_aht,'--g')
hold on
plot(C3,Ugs_aht,'--y')
hold on
plot(C4,Ugs_aht,'--c')
hold on
plot(C5,Ugs_aht,'--k')