How can I run multiple functions at once in MATLAB 7.7 (R2008b)?

6 views (last 30 days)
I have a function that takes a very long time to execute. I would like to run other tasks in MATLAB while my lengthy function is executing.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Sep 2009
You can use MATLAB callbacks to achieve this behavior.
Attached is an example MATLAB file that creates a GUI with three pushbuttons ('bench', 'P1' and 'P2'). Each pushbutton executes a callback. P1 and P2 will call 'fun', a subfunction of the MATLAB file which displays text at the MATLAB command window, and 'bench' will call BENCH, MATLAB's benchmark function.
To run the example, place the MATLAB file on your MATLAB path or navigate to the MATLAB file's directory. Then type 'makegui' at the MATLAB command prompt. The GUI appears with three pushbuttons.
BENCH takes some time to execute, so you can use the example to show that the functions called by P1 and P2 can interrupt BENCH. Start BENCH by pressing the 'bench' pushbutton, and then press P1 and P2. The callbacks to P1 and P2 will execute while the BENCH function is executing. (Note that execution isn't truly simultaneous. BENCH must pause while FUN executes.) In addition, you have access to the MATLAB command line while these functions are running.
For more on defining callbacks, see
MATLAB-->Creating Graphical User Interfaces-->Creating GUIs programmatically-->Programming the GUI-->Callbacks: An Overview

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2008b

Community Treasure Hunt

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

Start Hunting!