Dynamic array storage with for loop
古いコメントを表示
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)
採用された回答
その他の回答 (2 件)
Ameer Hamza
2020 年 5 月 18 日
編集済み: Ameer Hamza
2020 年 5 月 18 日
There are several syntax errors in your code. Compare it with the following code to see the issues
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;
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 = strings(1,13);
for i = 1:13
if C(i) <= 0.2
flow(i) = 'Bubble';
elseif C1(i) <= 0.89
flow(i) = 'Slug';
elseif C2(i) <= 0.98
flow(i) = 'Transition';
elseif C3(i) >= 1.00
flow(i) = 'Churn';
end
end
% end
Ugs = Ugs.';
Uls = Uls.';
Uls1 = Uls1.';
Uls2 = Uls2.';
Uls3 = Uls3.';
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)
Result
T =
13×9 table
Ugs Uls_aht Uls1_aht Uls2_aht Uls3_aht C C1 C2 C3
_____ ________ ________ ________ ________ _______ _______ _______ _______
0.047 0.058011 0.087634 0.11726 0.17527 0.28669 0.34186 0.38826 0.46448
0.061 0.058011 0.087634 0.11726 0.17527 0.29307 0.34824 0.39464 0.47086
0.288 0.058011 0.087634 0.11726 0.17527 0.35431 0.40948 0.45588 0.5321
0.344 0.058011 0.087634 0.11726 0.17527 0.36485 0.42002 0.46642 0.54264
0.404 0.058011 0.087634 0.11726 0.17527 0.37523 0.4304 0.4768 0.55302
0.544 0.058011 0.087634 0.11726 0.17527 0.39678 0.45195 0.49835 0.57457
0.709 0.058011 0.087634 0.11726 0.17527 0.41886 0.47404 0.52044 0.59666
0.945 0.058011 0.087634 0.11726 0.17527 0.44636 0.50154 0.54794 0.62416
1.418 0.058011 0.087634 0.11726 0.17527 0.4926 0.54777 0.59417 0.67039
1.891 0.058011 0.087634 0.11726 0.17527 0.53157 0.58674 0.63314 0.70936
2.363 0.058011 0.087634 0.11726 0.17527 0.56583 0.621 0.6674 0.74362
2.836 0.058011 0.087634 0.11726 0.17527 0.59687 0.65205 0.69844 0.77467
4.727 0.058011 0.087634 0.11726 0.17527 0.70049 0.75566 0.80206 0.87828
4 件のコメント
Temidayo BOBOYE
2020 年 5 月 19 日
編集済み: Temidayo BOBOYE
2020 年 5 月 19 日
Walter Roberson
2020 年 5 月 19 日
ndgrid() or meshgrid()
Temidayo BOBOYE
2020 年 5 月 21 日
Temidayo BOBOYE
2020 年 6 月 3 日
Walter Roberson
2020 年 5 月 18 日
flow = ones(1,13);
flow = string(flow);
for i = 1:13
if C(i) <= 0.2
flow(i) = 'Bubble';
elseif C1(i) <= 0.89
flow(i) = 'Slug';
elseif C2(i) <= 0.98
flow(i) = 'Transition';
elseif C3(i) >= 1.00
flow(i) = 'Churn';
end
end
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!