How to delete a file when closing Matlab?

4 ビュー (過去 30 日間)
Nicola Dall'Osto
Nicola Dall'Osto 2024 年 4 月 17 日
コメント済み: Aquatris 2024 年 4 月 17 日
I cerated a .mat file with a variable inside that serves as a sort of memory. I need to delete this file when closing Matlab or when I reopen Matlab. How can I do that? If I store the file in the temp folder of Matlab, it will be deleted every time I close Matlab or not?

回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2024 年 4 月 17 日
編集済み: Sulaymon Eshkabilov 2024 年 4 月 17 日
Use delete command the mat file called DONE.mat, e.g.:
delete('DONE.mat') % e.g.
One good option is to edit startup.m file
% Add the Path to the DONE.mat file that you want to delete
File_2_Delete = 'C:/Windows/Temp/DONE.mat';
% Check if the file exists
if exist(File_2_Delete , 'file') == 2
% Delete the file
delete(File_2_Delete);
disp(['File ', File_2_Delete, ' deleted at the MATLAB start!']);
else
disp(['File ', File_2_Delete, ' does not exist!']);
end
All the best.
  1 件のコメント
Aquatris
Aquatris 2024 年 4 月 17 日
Similar to a startup script, you can also create a finish script that would run while closing matlab, here is documentation for it. You can add a delete if exist command in both finish and startup scripts :)

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

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by