Main Content

clear

Remove objects from MATLAB client workspace

Syntax

Description

clear obj removes the object obj from the MATLAB® client workspace.

Note

To remove variables from the workspace of pool or cluster workers, use parfevalOnAll to run the clear function on the workers to preserve workspace transparency. If you try to use clear directly in a parfor-loop or spmd block, you encounter an error. For more information, see Ensure Transparency in parfor-Loops or spmd Statements.

example

Examples

collapse all

Create two job objects on the MATLAB Job Scheduler cluster myMJSCluster.

c = parcluster(myMJSCluster);
delete(c.Jobs) % Delete any existing jobs
job1 = createJob(c);
job2 = createJob(c);

Copy job1 to a new variable named job1copy, then clear job1 and job2 from the MATLAB workspace.

job1copy = job1;
clear job1 job2;

Restore the cleared job objects to the workspace using the cluster object c.Jobs property as j1 and j2.

j1 = c.Jobs(1);
j2 = c.Jobs(2);

Verify that the first job in the MATLAB Job Scheduler is identical to job1copy, while the second job is not.

isequal (job1copy,j1)
ans =
     1
isequal (job1copy,j2)
ans =
     0

Input Arguments

collapse all

Object to clear from the MATLAB workspace, specified as an object or an array of objects.

Tips

If the object obj references an object in the cluster, this function clears it from the workspace, but it remains in the cluster. You can restore obj to the workspace with the parcluster, findJob, or findTask function, or with the Jobs or Tasks property.

Version History

Introduced before R2006a