フィルターのクリア

How to save results in a file without overwritting previous results????

3 ビュー (過去 30 日間)
Javier Díez Martín
Javier Díez Martín 2022 年 4 月 26 日
コメント済み: Walter Roberson 2022 年 4 月 28 日
I want to open a file and save in it specific results of a simulation but without overwritting the previous ones tha I have saved.

回答 (1 件)

Chunru
Chunru 2022 年 4 月 27 日
Use append option when you save the data to files. [You can also use low-level fopen with option 'a+' for appending]
% create a file
a1 = [1 2 3];
save('test.txt', 'a1', '-ascii');
type test.txt
1.0000000e+00 2.0000000e+00 3.0000000e+00
%% Now save more data with append
a2 = [4 5 6];
save('test.txt', 'a2', '-ascii', '-append');
type test.txt
1.0000000e+00 2.0000000e+00 3.0000000e+00 4.0000000e+00 5.0000000e+00 6.0000000e+00
  2 件のコメント
Javier Díez Martín
Javier Díez Martín 2022 年 4 月 28 日
Thanks for your answer, it's very helpful. However, the programme that I am running is more complex than that, can I send you by email the whole Simulink file with the explanation of what I need?
Thanks in advance.
Walter Roberson
Walter Roberson 2022 年 4 月 28 日
writetable() and writematrix() support append options these days.
save() to a .mat file supports '-append'
save() to text suports '-append'
For binary files, fopen() with 'a' always appends to the end of the file (even if you have used fseek() to reposition.). fopen() with 'a+' starts at the end of the file, but permits you to fseek() and write at whatever position you are at.

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

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by