HELP: received error when trying to run two functions in parallel.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I am trying to run two functions in parallel so that they will plot a real-time graph at the same time. My code looks like:
tf = 60;
parfor i = 1:2
if i == 1
disp('OpenBCI start');
[EEGfilt, EMGfiltNormal, t] = OpenBCIfunction(tf);
else
disp('Flex Sensor start');
[R_f0, R_f1, R_f2, R_f4, R_f5, t] = Glovefunction(tf);
end
end
When I run the code, I get the command window to display "OpenBCI start" and "Flex Sensor start". However, I never get a graph to show up and right after "Flex Sensor start" I recieve this message in the command window.
Caught "std::exception" Exception message is:
Unknown exception
Error using OpenBCI_Glove_Parallel (line 9)
Unknown exception
How do I fix this so I can get these two functions to run in parallel and output individual live graphs? (The graphs are being plotted within the functions.)
0 Kommentare
Antworten (1)
Raymond Norris
am 9 Apr. 2021
Bearbeitet: Raymond Norris
am 9 Apr. 2021
It's unclear to me what could be causing the exception. Might need to troubleshoot this with Technical Support (support@mathworks.com).
If the functions OpenBCIfunction and Glovefunction generate the graphs, then they're going to generate them via the headless workers -- i.e. no graphs. However, if the initial graphs are created a prior, then the functions can send data back to the main MATLAB, which can intern update the graphs. Take a look at parallel.pool.DataQueue for an example that might work for you.
2 Kommentare
Raymond Norris
am 9 Apr. 2021
I would suggest two data queues. Here's a sketch of what you could do.
parpool('local',2);
glove_h = figure();
glove_q = parallel.pool.DataQueue;
afterEach(glove_q,@(data)updateGlovePlot(glove_h,data));
bci_h = figure();
bci_q = parallel.pool.DataQueue;
afterEach(bci_q,@(data)updateBciPlot(bci_h,data);
parfor ii = 1:2
if ii == 1
disp('Flex Sensor start');
[R_f0, R_f1, R_f2, R_f4, R_f5, t] = Glovefunction(tf);
send(glove_q,[ data(s) to be passed to update the plot ])
else
disp('OpenBCI start');
[EEGfilt, EMGfiltNormal, t] = OpenBCIfunction(tf);
send(bci_q,[ data(s) to be passed to update the plot ]);
end
end
The "data(s) to be passed to update the plot" is probably based on the variables passed back form calling the Glovefunction / OpenBCIfunction.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!