Access variables in parallel computing

조회 수: 4 (최근 30일)
John Tuff
John Tuff 2022년 4월 4일
댓글: Alice 2024년 6월 18일
Hello everyone,
I have a problem that I'm unsure how to solve:
I have a video camera recording during a task that gives a TTL signal per frame (approx 75 Hz) that I would like to count in the background while the main task is running. However to synchronize the signals I would like MATLAB to access the counter variable at certain points during the task and return the frame number. I have tried using the parallel computing toolbox, however I do not know how to access the counter variable in the background. Is there any way of doing this on one machine or how could this be best achieved?
Thanks in advance for the help,
John
  댓글 수: 3
John Tuff
John Tuff 2022년 4월 5일
Thank you Raymond, what you've described is exactly what I am trying to implement, the counter running in the background and the main task poking the background to get the current status of the counter variable.
The unspecific answer to how close I need it is 'as close as I can get'. How much of a delay would be expected? It doesn't have to be single digit millisecond precise, double digits would be great, low triple digit would be acceptable.
I have the Parallel Computing Toolbox, and I am currently running Version R2021b.
Alice
Alice 2024년 6월 18일
Hi,
A bit late, but I have the same question : I need to access a variable in my main program that is being modified in the background. I can access it sometimes but it will stop updating the variable after some time and give me a constant value when the actual variable is changing, so I think that I'm not going about it the right way.
How did you solve your problem?
Thanks in advance,
Alice

댓글을 달려면 로그인하십시오.

답변 (2개)

Steven Lord
Steven Lord 2022년 4월 4일
The functionality in MATLAB to perform background processing may be of use to you.
  댓글 수: 2
John Tuff
John Tuff 2022년 4월 4일
Thank you Steven for your answer. I have tried to use background processing, however in my case, the background is constantly running, and the foreground would need to access a variable from the background. I have not so far been able to find a solution to this so my question is whether this is possible at all in MATLAB.
Steven Lord
Steven Lord 2022년 4월 4일
Doesn't this paragraph from the documentation page address that?
"Use parfeval with the background pool to run a function in the background. parfeval immediately returns a Future object that represents the function running in the background. To get results from the Future, call fetchOutputs."

댓글을 달려면 로그인하십시오.


John Tuff
John Tuff 2022년 4월 5일
I have tried the following:
This is just my dummy counter to see whether I can access the background.
function x = counter
x = 0;
it = true;
while it == true
x= x+1;
pause(0.5);
%disp(x);
end
In the foreground I start by using parfeval
f= parfeval(backgroundPool,@counter,1)
I would try calling fetchOutputs, but if I do, it waits until the counter function is finished before returning the result.
p = fetchOutputs(f);
for i= 1:10
p = fetchOutputs(f);
disp(p);
disp(i);
pause(0.1);
end
Is there any issue in how I call the functions?

카테고리

Help CenterFile Exchange에서 Parallel Computing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by