MATLAB: How to delete a .csv in the directory

csv

I have a csv that is a subset of the original data (part of my script is to create it), and I am looking for a way to delete the file at the begining of my script each time since a new one is always created. Is there a way to do such a thing?
It isn't in my main directory, but is in a subfolder from it.

Best Answer

delete subfolder\filename.csv %relative path to current directory
But you shouldn't rely on the main directory and instead use full paths everywhere in your script. This way the data can be located anywhere independently on where the code is.
datafolder = 'C:\somewhere\somefolder'
%importing some data with whichever function you normally use. Using readmatrix here for demo:
filename = 'somefile.csv';
data = readmatrix(fullfile(datafolder, filename));
%deleting a particular file in the data folder:
delete(fullfile(datafolder, 'somefile.txt'));
%saving an image
imwrite(img, fullfile(datafolder, 'fancyimage.png'))
%etc.