send - Send data to DataQueue or

  PollableDataQueue - MATLAB ([original](https://in.mathworks.com/help/matlab/ref/parallel.pool.dataqueue.send.html)) ([raw](?raw))

Main Content

Send data to DataQueue orPollableDataQueue

Syntax

Description

send([q](#mw%5F6aa333f7-b667-4f8e-8931-b6bcf90a0a6d),[data](#mw%5F03bae935-1bb4-400a-b35f-47ce8d484f5d)) sends an item of data with value data to a queue q. Send data from the background or your current MATLAB® session.

You can send data from a function that you run on a parallel pool if you have Parallel Computing Toolbox™. For details, see send (Parallel Computing Toolbox).

example

Examples

collapse all

This example shows how to automatically process data in your current MATLAB session that you send from the background.

Create a DataQueue object. After each item of data is received on the DataQueue in your current MATLAB session, automatically display that item using the disp function.

q = parallel.pool.DataQueue; afterEach(q,@disp);

The helper function magicWithSend defined at the end of this example sends the sum of a magic square to a DataQueue or PollableDataQueue object, then returns that magic square.

Use parfeval and backgroundPool to run the function magicWithSend in the background.

f = parfeval(backgroundPool,@magicWithSend,1,q,3);

The sum is displayed before you fetch outputs from the future. To retrieve the output from the background, use fetchOutputs. MATLAB returns the output once the execution of magicWithSend is complete.

ans = 3×3

 8     1     6
 3     5     7
 4     9     2

Define Helper Function

Define the helper function magicWithSend. The function creates a magic square, then sends the sum of the magic square to a DataQueue or PollableDataQueue object. After the sum is sent, the function returns the magic square.

function X = magicWithSend(q,n) X = magic(n); s = sum(X,'all'); send(q,s); end

Input Arguments

collapse all

Queue, specified as a parallel.pool.DataQueue orparallel.pool.PollableDataQueue object.

Example: q = parallel.pool.DataQueue

Example: q = parallel.pool.PollableDataQueue

Data to send, specified as a scalar, vector, matrix, or multidimensional array.

Example: send(q,"A message");

Example: send(q,magic(3));

Extended Capabilities

Version History

Introduced in R2017a