Thread implemented in MATLAB in a timer

Hello,
I have two processes (one for a camera that runs through a camera function and one for a robot that runs through a robot function), and I'd like to set up a thread to run them in parallel.
I'd like the robot process to run in the background if possible. I searched the internet and found parfeval but I don't really understand how it works.
I don't really understand how it works. Can you advise me on how to do this?

 採用された回答

Abhaya
Abhaya 2024 年 12 月 5 日

1 投票

Hi Claire,
I understand that you want to run two processes in parallel: one for a camera function and another for a robot function, with the robot process running asynchronously in the background.
To achieve this, you can use MATLAB ‘parfeval’ function along with ‘parpool’ function. The MATLAB ‘parpool’ function starts a parallel pool of workers, while the MATLAB ‘parfeval’ function is used to run functions in the background.
To set this up, please refer to the steps given below.
  • Start the parallel pool with two workers.
parpool(2);
  • Run the camera and robot processes in the background.
f1 = parfeval(@cameraProcess, 0); % The second parameter represents number of output. ‘0’ means there is no output.
f2 = parfeval(@robotProcess, 0);
For more information, please refer to the MATLAB documentation for ‘parpool’ and ‘parfeval’ functions.
Additionally, you might find this MATLAB community discussion helpful.
Hope this helps in solving your query.

3 件のコメント

Claire
Claire 2024 年 12 月 5 日
Thanks for your answer.
I am not sure how to implement that with a timer. I have the main timer function running both process.
app.MeTimer = timer(...
'ExecutionMode', 'fixedSpacing', ... % 'fixedRate', ... % Run timer repeatedly
'Period', Period, ... % Period (second)
'BusyMode', 'queue', ... %'queue',... % Waits until the currently executing callback function finishes before queuing the next execution of the timer callback function.
'TimerFcn', @app.Streaming); % Specify callback function
Do I declare the parpool and the parfeval before the timer?
Claire
Claire 2024 年 12 月 5 日
Found how to do it and it works. Thanks for your help
Jakob
Jakob 2025 年 5 月 7 日
would you mind sharing your solution?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeParallel Computing Fundamentals についてさらに検索

タグ

質問済み:

2024 年 12 月 4 日

コメント済み:

2025 年 5 月 7 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by