Matlab is inherently a single-threaded interpreter and was designed for applications with a single point of execution. When working with TinyOS and sensor networks, however, it is more natural to use an event-driven programming model. Usually, we have two types of events that drive our application: clock events and/or message received events.
Designing event-driven applications in Matlab are actually quite simple if you use the following guidelines:
Use this file to setup your matlab path and global variables for this app. It needs to be called only once per matlab session.
It is easiest to use the following 5 types of functions when writing event-driven applications
While this is bad programming style, Matlab functions are unfortunately pass-by-value, which creates some serious problems for event-driven applications and Matlab objects. If/when you encounter these problems, you have two options: store your data in a Java object, which is passed by reference within matlab or store your data in a matlab global variable which can be imported into any function that also declares it global.
As an excercise, write a MessegeListener class that buffers messages. Then, use the clock event handler in your application to read the buffers.