フィルターのクリア

How to make table in loop

3 ビュー (過去 30 日間)
Firas Sidqi
Firas Sidqi 2021 年 10 月 2 日
コメント済み: Firas Sidqi 2021 年 10 月 2 日
If I have yhe code below, and I want the table to record all my iteration, how to do the table function? Since it's only displaying the last iteration only.
Input Lambda as 9 and Total Power as 450
clc
clear all
P=0;
kanan = input('Masukkan Lambda Awal, Lambda 1 : ')
kiri = 0;
Lmbd = 0;
P = 0;
a = [ 0.0025 8.4 225 ];
b = [ 0.0081 6.3 729 ];
c = [ 0.0025 7.5 400 ];
Total_P = input('Total Power, P : ')
FC1 = 0.8;
FC2 = 1.02;
FC3 = 0.9;
F1 = FC1*a;
F2 = FC2*b;
F3 = FC3*c;
Iterasi = 1;
Lmbd = kanan;
P1 = (Lmbd - F1(2)) / (F1(1)*2);
P2 = (Lmbd - F2(2)) / (F2(1)*2);
P3 = (Lmbd - F3(2)) / (F3(1)*2);
P = P1 + P2 + P3;
while abs(P - Total_P) >= 0.0001
Iterasi = Iterasi + 1;
Lmbd = abs((kanan + kiri) / 2);
P1 = (Lmbd - F1(2)) / (F1(1)*2);
P2 = (Lmbd - F2(2)) / (F2(1)*2);
P3 = (Lmbd - F3(2)) / (F3(1)*2);
P = P1 + P2 + P3;
if P > Total_P
kanan = Lmbd;
end
if P < Total_P
kiri = Lmbd;
end
end
% P1
% P2
% P3
T = table(Iterasi, P1, P2, P3, P, Lmbd);

採用された回答

C B
C B 2021 年 10 月 2 日
編集済み: C B 2021 年 10 月 2 日
to record all iteration, you need to store them in loop.
As shown in below code.
For More information check Add Rows from Cell Array
clc
clear all
P=0;
TUpdated={};
kanan = input('Masukkan Lambda Awal, Lambda 1 : ')
kiri = 0;
Lmbd = 0;
P = 0;
a = [ 0.0025 8.4 225 ];
b = [ 0.0081 6.3 729 ];
c = [ 0.0025 7.5 400 ];
Total_P = input('Total Power, P : ')
FC1 = 0.8;
FC2 = 1.02;
FC3 = 0.9;
F1 = FC1*a;
F2 = FC2*b;
F3 = FC3*c;
Iterasi = 1;
Lmbd = kanan;
P1 = (Lmbd - F1(2)) / (F1(1)*2);
P2 = (Lmbd - F2(2)) / (F2(1)*2);
P3 = (Lmbd - F3(2)) / (F3(1)*2);
P = P1 + P2 + P3;
while abs(P - Total_P) >= 0.0001
Iterasi = Iterasi + 1;
Lmbd = abs((kanan + kiri) / 2);
P1 = (Lmbd - F1(2)) / (F1(1)*2);
P2 = (Lmbd - F2(2)) / (F2(1)*2);
P3 = (Lmbd - F3(2)) / (F3(1)*2);
P = P1 + P2 + P3;
if P > Total_P
kanan = Lmbd;
end
if P < Total_P
kiri = Lmbd;
end
TUpdated = [TUpdated; table(Iterasi, P1, P2, P3, P, Lmbd)];
end
TUpdated
  1 件のコメント
Firas Sidqi
Firas Sidqi 2021 年 10 月 2 日
Thank you Mr. Bhavsar. It solve my question well. I need to learn more about how arrays work in Matlab. The one that impress me is how you store the table using array {}, not matrix [].

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by