Documentation

delete

Remove files or objects

Syntax

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

Description

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 fileName is the command syntax. Delete multiple files by appending filenames, separated by spaces. When filenames contain space characters, you must use the function form.

delete(h) deletes the graphics object h. If h an array, the function deletes all objects in the array. h can also contain the figure Number.

The function deletes objects without requesting verification, even if when the objects are figure 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.

As delete does not ask for confirmation, to avoid accidentally losing files or graphics objects, be 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.

Examples

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

delete('/mytests/*.mat')

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

fig = figure;
ax = axes;
...
delete(ax)

The axes is deleted, but the figure remain. The axes variable ax remains in the workspace, but no longer refers to an object.

Use an array to delete all the line objects created by plot:

H = plot(magic(5));

Pass the array H to delete:

delete(H)

See Also

| | |

Was this topic helpful?