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.


Retrieve next available unread FevalFuture outputs


[idx,B1,B2,...,Bn] = fetchNext(F)
[idx,B1,B2,...,Bn] = fetchNext(F,TIMEOUT)


[idx,B1,B2,...,Bn] = fetchNext(F) waits for an unread FevalFuture in the array of futures F to finish, and then returns the linear index of that future in array F as idx, along with the future's results in B1,B2,...,Bn. Before this call, the 'Read' property of the particular future is false; afterward it is true.

[idx,B1,B2,...,Bn] = fetchNext(F,TIMEOUT) waits no longer than TIMEOUT seconds for a result to become available. If the timeout expires before any result becomes available, all output arguments are empty.

If there are no futures in F whose 'Read' property is false, then an error is reported. You can check whether there are any unread futures using anyUnread = ~all([F.Read]).

If the element of F which has become finished encountered an error during execution, that error will be thrown by fetchNext. However, that future's 'Read' property is set true, so that any subsequent calls to fetchNext can proceed.


Request several function evaluations, and update a progress bar while waiting for completion.

N = 100;
for idx = N:-1:1
    % Compute the rank of N magic squares
    F(idx) = parfeval(@rank,1,magic(idx));
% Build a waitbar to track progress
h = waitbar(0,'Waiting for FevalFutures to complete...');
results = zeros(1,N);
for idx = 1:N
    [completedIdx,thisResult] = fetchNext(F);
    % store the result
    results(completedIdx) = thisResult;
    % update waitbar
    waitbar(idx/N,h,sprintf('Latest result: %d',thisResult));


The fetchNext function returns the linear index of the future from its array. If instead, you need the subscript values of a multidimensional array, you can use the ind2sub function to convert the values.

Introduced in R2013b

Was this topic helpful?