I am writing a solution that manages data from an eye tracker. I currently hold the data in a N x 5 matrix, with the following columns:
X Position, Y Position, timestamp, Velocity, Acceleration
Each row represents a single sample from the eye tracker (which runs at 1000Hz).
At present, I access the data in the form of a matrix – e.g. if I want to access the velocity for sample #600, I use ‘dataStream(600,4)’.
This is fine, but I’d prefer my code to be more readable. The ‘4’ could be confusing; something like dataStream.velocity(600) would be ideal. I understand that this would be a simple use of STRUCT. However, there are situations in which I need to copy an entire sample (i.e. all columns from one row of my matrix). As I understand it, this would not easily be achieved in a STRUCT object, as the various arrays in each STRUCT sub-heading are not intrinsically linked. I would have to (I think) copy each element separately, for example if I wanted to copy sample #100, I believe I would need to copy dataStream.xPos(100), dataStream.yPos(100), dataStream.timestamp(100) and so on separately.
Is there something I’m missing with regards to management of STRUCTs, or would I be better off saving the hassle and sticking with the matrix approach?
If it is just for an increased readability, I would not use structs, but rather use an quite simple approach by defining variables for the different columns of your data matrix. See for instance:
With this variables you can write quite meaningful queries, for instance, instead of
dataStream(600,1)you would write:Note that you also could define more complex queries, for instance
to query the multiple columns at once.