Azzera filtri
Azzera filtri

Running two sections of Matlab code in parallel. is this possible?

98 visualizzazioni (ultimi 30 giorni)
I have a Matlab code that I need to run two sections at the same time as part of a control system.
It roughly looks like this
%%Section 1
logs data during specified time and inputted to a control system
%%Section 2
takes photos and information from photo is also used in the control system
is this possible and if so how?

Risposta accettata

Walter Roberson
Walter Roberson il 10 Ott 2017
It is generally possible using the Parallel Computing toolbox.
parpool(2)
spmd
if labidx == 1
collect_for = 15; %minutes
start_time = now; %days
end_time = start_time + collect_for/60 / 24; %days
while now < end_time
data_from_camera = labReceive(2);
%use the data from the camera to figure
%out how to control, send commands to the
%control system, and read log data from the
%control system
...
end
elseif labidx == 2
... set up camera
while true
... grab a picture
labSend(1, image_from_camera);
end
end
end
That said: it is common that you can do either data collection from the instrument or taking the pictures asynchronously, and have the availability of data signaled by a callback routine being called. When you can use this approach, you only need a single MATLAB proccess, as the interrupts and buffer management are handled by MATLAB.
Also note: you cannot update the graphics display from any worker (parfor, spmd, batch, parfeval). If you need to update the graphics display then you need to approach the parallelism slightly differently. The techniques became a bit easier in R2017a.

Più risposte (0)

Categorie

Scopri di più su Entering Commands in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by