Save values of power in a file without overwritting previous ones
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 28 Apr. 2022
What is the difference between this question and https://www.mathworks.com/matlabcentral/answers/1705395-how-to-save-results-in-a-file-without-overwritting-previous-results?s_tid=srchtitle ?
Antworten (1)
Walter Roberson
am 28 Apr. 2022
P = 1:2; Q = 11:12;
save ('PQ.txt','P','Q','-ascii','-append')
dbtype PQ.txt
P = 21:22; Q = 31:32;
save ('PQ.txt','P','Q','-ascii','-append')
dbtype PQ.txt
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Workspace Variables and MAT-Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!