Clear Filters
Clear Filters

How to delete temp files generated by simulink at the end of each iteration of a for loop?

77 views (last 30 days)
Hi to everyone!
I'm running a lot of simulink simulation model through a for loop. At the end of the for loop I want to clear the temporany file folder because after a few iterations it fills up the memory of my C drive. Can someone help me please? Thankyou in advance

Answers (1)

Deep
Deep on 9 Jul 2023
for i = 1:n
% Run your Simulink model here...
% Get system's temporary directory.
% Use 'cacheFolder = pwd;' instead to delete .slxc files in the current path.
cacheFolder = tempdir;
files = dir(fullfile(cacheFolder, '*.slxc')); % Look for Simulink cache files
for j = 1:length(files)
delete(fullfile(files(j).folder, files(j).name)); % Delete each file
end
end
When working on this, double-check the path and maybe do a dry-run with displaying the files that would be deleted before actually deleting anything.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!