Delete files or objects
filename from disk, without requesting verification.
By default, the specified file is permanently deleted. To change whether the file
is permanently deleted or sent to the recycle folder, go to the
Home tab, and in the Environment
section, click Preferences. Select MATLAB > General and in the Deleting files section, select from
the available options. Alternatively, you can use the
When file recycling is on, the
delete function moves deleted
files to a location specific to the platform:
Windows® — Recycle bin.
macOS — Trash.
Linux® platforms — Subfolder with the prefix
MATLAB_Files_in the system temporary folder, as returned by the
On macOS, file recycling is not applied to files deleted from network drives.
Delete Files in Folder
Delete all files in the current folder with a
Delete Graphics Objects
Delete a graphics object and a graphics object array.
Create a bar chart and plot five lines. Then delete the bar chart.
b = bar(1:5);
P = plot(magic(5));
Bar object variable
b remains in the workspace, but no longer refers to an object.
b = handle to deleted Bar
Delete all the
Line objects created by
filename — File name
character vector | string scalar
File name to delete, specified as a character vector or string scalar.
filename can be an absolute or relative path and
can include wildcards (*). To delete files from a remote location,
fileName must contain a full path specified as a
uniform resource locator (URL). For more information, see Work with Remote Data.
obj — Object
single object | array of objects
Object to delete, specified as a single object or an array of objects.
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
Version HistoryIntroduced before R2006a
R2020a: Wildcard expression
*.* on UNIX platforms matches only files
that have an extension
Starting in R2020a, on UNIX® platforms, the wildcard expression
*.* no longer
matches folders or files without an extension. In previous releases, the expression
matches folders or files regardless of extension, including files without an
extension. This change of behavior does not apply to Microsoft®