MATLAB: Do I receive “MATLAB:Un​definedFun​ction” error when trying to destroy jobs in the scheduler in Parallel Computing Toolbox R2011a

Parallel Computing Toolbox

I am trying to destroy jobs associated with my scheduler. When I execute the following commands:
>> sched = findResource('configuration','type','local')
>> jobs = sched.Jobs;
>> destroy(jobs);
I receive the following error:
MATLAB:UndefinedFunction
Undefined function 'destroy' for input arguments of type 'double'.

Best Answer

This error occurs when there are no jobs in the scheduler for destruction. In such a situation:
>> jobs = sched.Jobs
will set the output variable jobs to an empty matrix
jobs =
Empty matrix: 0-by-1
To work around this you should add the following check:
if(~isempty(jobs))
destroy(jobs)
end