Documentation Center

  • Trial Software
  • Product Updates


Remove files or objects


delete('fileName1', 'filename2', ...)
delete fileName


delete('fileName1', 'filename2', ...) deletes the files fileName1, fileName2, and so on, from the disk. fileName is a string and can be an absolute path or a path relative to the current folder. fileName also can include wildcards (*).

delete(h) deletes the graphics object with handle h. h can also be a vector or matrix of handles. Delete multiple objects by appending their handles as additional arguments, separated by commas. The function deletes objects without requesting verification, even if when they are windows.

delete(handle_array) is a method of the handle class. It removes from memory the handle objects referenced by handle_array.

When deleted, any references to the objects in handle_array become invalid. To remove the handle variables, use the clear function.

delete fileName is the command syntax. Delete multiple files by appending filenames, separated by spaces. When filenames contain space characters, you must use the functional form.

As delete does not ask for confirmation, to avoid accidentally losing files or graphics objects, make sure to specify accurately the items to delete. To move files to a different location when running delete, use the General preference for Deleting files, or the recycle function.

The delete function deletes files and graphics objects only. To delete folders, use rmdir.


Delete all files with a .mat extension in the ../mytests/ folder:


Create a figure and an axes, and then delete the axes:

hf = figure, ha = axes

hf =
ha =


The axes is deleted, but the figure remain. The axes handle ha remains in the workspace but no longer points to an object.

See Also

| |

Was this topic helpful?