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).
Examples
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
Queue, specified as a parallel.pool.DataQueue
orparallel.pool.PollableDataQueue
object.
- If
q
is a DataQueue, use afterEach to automatically process data when it is received in the current MATLAB session. - If
q
is a PollableDataQueue object, use poll to manually retrieve data after it is received in the current MATLAB session.
If you close aPollableDataQueue
object using the close function, you can no longer send data to the queue. Any attempt to send data to the queue results in an error. (since R2025a)
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