My day to day work flow is something like this:
- acquire raw data (~50GB)
- parse raw data timing-information and build raw data structure (struct / object) from timing-information (what event occurred when, in which order, in what file, what other events occurred at the same time, etc …)
- load only the necessary parts of raw data into struct / object as selected from previous timing information (basically this is a way to sub-select data)
- for each raw data chunk, calculate / extract certain metrics like RMS of signal, events where data > threshold, d’ / z-score, and save them with struct / object
- given the the previously calculated metrics, load some raw-data of same time episodes from different data channel and compare certain things, etc …
- visualize results x, y, z
I have two ways of dealing with this kind of data / workflow:
- use struct()
- use objects
There are certain advantages / disadvantages to both cases:
-
struct:
- can add properties / fields on the fly
- have to check for state of struct every single time that I pass a struct to a function
- keep re-writing certain functions because every time that I change the struct slightly I a) tend to forget that a function already exists for it or b) I write a new version that handles a special case of the struct state.
-
objects:
- using ‘get.property()’ methods, I can check the state of a property before it get’s accessed inside a function / method -> allows to do data consistency checks.
- I always know which methods work with my object, since they are part of the object definition.
- need to
clear classesevery time I add a new property or method – very annoying!
Now my question is: how do other people deal with this kind of situation? how do you organize your data? in structs? in objects? how do you handle state checks? is there a way to do ‘stateless’ programming in matlab?
I like to use objects. You don’t need to call clear classes on every change. It is enough to delete all instances of the “old” object.
Two very powerful additions I inherit often are handle and dynamicprops.
About the consistency checks – why no do them when you use set.property?
Edit 1:
a simplified class that uses the database:
Edit 2: Example for Event – Observer
and a listener:
The example:
you can then observe when you do a:
a.data=rand(100,3)– the plot will change immediatly.Edit 3: a simple saving class
Example:
look at `whos’:
although you can do calculations like
d = a.data-b–atakes just 60 bytes in memory – as opposed to the ~8 MB ofb.Edit 4: trick for often changing functions. When you put the logic in external commands matlab will not complain when you change the function definition there.