I want to save dat from Simulink into a file without overwritting the previous results

조회 수: 2 (최근 30일)
Hi everyone!
I am triying to save P and Q results in a file or in a txt but the code doesn´t run properly.
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

답변 (1개)

Lokesh
Lokesh 2023년 9월 25일
Hi Martin,
I understand that you want to save data from Simulink into a file without overwriting the previous results.
The "save" function is correctly used to save the values of P and Q to a text file named 'PQ.txt'. The '-append' flag ensures that the data is appended to the file rather than overwriting it on each iteration.
However, there are a few issues with the code you provided. Here are some suggestions for the same:
  • The range for "Ub" appears to be incorrect. The correct syntax for using ‘for’ loop with a step size counter would be “Start value: Step size : End value”. However, in the first line of code, it is specified that ‘for Ub = ( 378:462:10.5)’ which signifies that step size (462) that is larger than the range itself. Please adjust the range accordingly. You can refer to the below documentation to know more about the usage of “for” loop in MATLAB: https://www.mathworks.com/help/matlab/ref/for.html
  • It seems that you are using the same variable names "PR" and "QL" for both the loop counters and the loop variables. To avoid confusion and errors, it is better to use different variable names.
  • Inside the nested loops, you need to calculate the values of "P" and "Q" based on your specific requirements.
I hope this resolves your issue.
Best Regards,
Lokesh

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by