Save values of power in a file without overwritting previous ones
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2022-4-28
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 ?
回答(1 个)
Walter Roberson
2022-4-28
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!