Simultaneously run a function and record a video
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I am starting to become very disappointed by matlab. After a long search I found at least a workaround to run two functions simultaneously using parallel processing.
It basically looks like this:
parfor i = 1:2
if i==1
output_function_x;
else
start(video);
end
However, I get the error message: Error using parallel_function (line 589) Undefined function 'start' for input arguments of type 'double'.
Apparently, the functions you can use inside a parfor loop are limited, and video recording is not possible?? Is there any workaround? I need to record a video while performing manipulations (output_function_x produces some hardware outputs) that have to be synchronized to the video.
But then how do matlab programs like "scanimage" work that control whole microscopes, apparently it must be possible to have video recording and create motor outputs at the same time...
0 comentarios
Respuestas (1)
Walter Roberson
el 18 de Dic. de 2012
As a first approximation: objects and handle graphics created in one session cannot be passed to another session. (There might be mechanisms that I have not noticed yet.)
MATLAB sessions have their own address space, and there is no shared object memory between them, so when the new session gets created the object variable just becomes a reference to something that does not exist in the new address space.
The sharing mechanisms are similar to what would happen in a message-passing system: MATLAB can pass in a "message" which is a data array, and it can receive back a "message" that is the results, but what would be a valid pointer in the original session is just a numeric value in the second.
Only one session has access to graphics: MATLAB graphics are all handled by a single JAVA thread that does not have access to the memory of the other sessions.
It is possible that you might be able to get further using a different kind of parallelism, but I am not certain about that.
2 comentarios
Walter Roberson
el 19 de Dic. de 2012
Unfortunately I have never had PCT to test with. Which is one reason I have never investigated the more obscure behaviors :(
I suggest a test: try starting a timer that does something like disp() a string at regular intervals, and then parfor something that keeps the session busy for a bit, and see if the values are displayed. Or a variation on this: have the timer append "now" to an array at nominally regular intervals, and parfor() something, and then when the parfor finishes, stop the timer and look at the timestamps. This test will allow you to determine whether the timer is active at regular intervals while the parfor() happens, or if instead the timer callbacks are queued until right after the parfor(), or if instead the timer callbacks just don't happen during the parfor().
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!