Save values of power in a file without overwritting previous ones

1 回表示 (過去 30 日間)
Javier Díez Martín
Javier Díez Martín 2022 年 4 月 28 日
Hi everyone!
I am triying to save powers' results in a file whitout overwritting the previous ones. The process that I have to do is: change taps from 1 to 9 and in each tap obtain the value of P and Q in a file or txt while the load is varying its active power and reactive power values (see Simulink file). The code that I have written is the next one; where Ub is the voltage that offers each tap, PR and QL the power of the load, P and Q the results needed:
for Ub=(378:462:10.5)
PR=0;
QL=0;
while (PR~=100000 && QL~=100000)
for PR=(0:100000:25000)
for QL=(0:100000:25000)
Pact=P;
Qreact=Q;
save ('PQ.txt','P','Q','-ascii','-append')
end
end
end
end
Thanks in advance.
  2 件のコメント
Javier Díez Martín
Javier Díez Martín 2022 年 5 月 2 日
The difference is that here you have all I have to do, with attached files and the programmation code that I have made.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 4 月 28 日
P = 1:2; Q = 11:12;
save ('PQ.txt','P','Q','-ascii','-append')
dbtype PQ.txt
1 1.0000000e+00 2.0000000e+00 2 1.1000000e+01 1.2000000e+01
P = 21:22; Q = 31:32;
save ('PQ.txt','P','Q','-ascii','-append')
dbtype PQ.txt
1 1.0000000e+00 2.0000000e+00 2 1.1000000e+01 1.2000000e+01 3 2.1000000e+01 2.2000000e+01 4 3.1000000e+01 3.2000000e+01
You can see from this that save -append is working to add additional information.
However, save -ascii makes no attempt to distinguish between the variables. It does not write any comment in showing the names of the variables or where the beginning of the variables are.
As you have been advised before (in multiple places), writetable() and writematrix() and writecell() can be used to append data to a text file, and you can also fopen() with 'a' and write data in yourself with fprintf()
H = {'%experiment#1', 'reaction_rate'; 83 19.2};
writecell(H, 'PQ.txt', 'writemode', 'append', 'delimiter', '\t');
dbtype PQ.txt
1 1.0000000e+00 2.0000000e+00 2 1.1000000e+01 1.2000000e+01 3 2.1000000e+01 2.2000000e+01 4 3.1000000e+01 3.2000000e+01 5 %experiment#1 reaction_rate 6 83 19.2

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by