How to run two different programs in matlab ?
34 views (last 30 days)
Show older comments
Hello!!
I have to run two different programs in matlab simultaneusly. Parallel Computing Toolbox is not an opcion.
The situation is: i have to show a moving image while analyze data in other program,both are totally independent.
I wish you can help me. Thank you!!
0 Comments
Answers (4)
Daniel Shub
on 11 Oct 2012
Assuming that running a bit of program 1 followed by a bit of program 2 qualifies as simultaneously, there are a number of ways of doing it.
Multiprocess: The multiprocess approach requires each program to be run as a process with its own resources. The OS then handles the context switching between the processes/programs. The multiprocess approach tends to be the best approach for two long running independent programs. The launch two instances of MATLAB falls into this category, but the category is much wider than that. I believe parfor and the PCT essentially take a multiprocess approach
Multithread: The multithread approach requires a single program to create a thread for each program. These threads share some resources, but also have some independent resources. The multithread approach tends to be the best approach for two long running dependent programs. While many of the built in MATLAB functions are multithreaded, user space MATLAB is designed to be single threaded. There is no direct way to spawn threads, although you can from a mex of java program.
Single thread: The single thread approach involves combining your two program into one program that does both things simultaneously. The use of callbacks, the event queue, and timers, can make this easier. This approach is best for short running dependent programs.
9 Comments
Walter Roberson
on 23 Oct 2012
I believe that psychtoolbox is built with an implicit programming model of "soft realtime", which is a model used when events do not need to happen at exact intervals but instead have a window of time to occur in, making it acceptable for the CPU to be doing other operations as long as the other operations do not take total control of the CPU for long enough to block the event from being completely processed by the end of its time window. As the time window gets shorter and shorter, it becomes less and less practical to do other things and the model becomes "hard real-time".
MATLAB itself is not suitable for "hard real-time", but some of the Simulink toolboxes can be used to generate real-time code to be downloaded into a system that is running a real-time operating system.
If the nature of your drawing work requires that you hook onto the vertical sync pulse of a CRT and use no more than a millisecond or so to rewrite the hardware graphics buffer memory, then MATLAB is not a suitable tool. If, though, you can get away with double-buffering frames any time during the screen draw, then you have a much greater window of opportunity and "soft" real-time becomes plausible with the aid of the psychtoolbox extensions.
You would not, in such a situation, use explicit creation of two tasks. Instead, you would start the data acquisition in background mode, allowing it to interrupt and write to memory from time to time.
ARPIT
on 30 May 2017
can you kindly let me know how you finally executed it? I also plan to do something similar
1 Comment
Walter Roberson
on 31 May 2017
If you need to display images at precise times, please look at Psychtoolbox
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!