Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

cancel (FevalFuture)

Cancel queued or running future

Syntax

cancel(F)

Description

cancel(F) stops the queued and running futures contained in F. No action is taken for finished futures. Each element of F that is not already in state 'finished' has its State property set to 'finished', and its Error property is set to contain an MException indicating that execution was cancelled.

Examples

Run a function several times until a satisfactory result is found. In this case, the array of futures F is cancelled when a result is greater than 0.95.

N = 100;
for idx = N:-1:1
    F(idx) = parfeval(@rand,1); % Create a random scalar
end
result = NaN; % No result yet.
for idx = 1:N
    [~, thisResult] = fetchNext(F);
    if thisResult > 0.95
        result = thisResult;
        % Have all the results needed, so break
        break;
    end
end
% With required result, cancel any remaining futures
cancel(F)
result

Introduced in R2013b

Was this topic helpful?