I am developing a certain feature for a high-order finite element simulation algorithm in Matlab and I am wondering what is a good way of implementing a certain task. I believe I am facing a somewhat common problem, but after doing some digging, I'm not really finding a good solution.
Basically, I have a long list of ID's (corresponding to certain nodes on my mesh), where each ID is associated with small data set. Then when I am running my solver, I need to access the data associated with these nodes and update the data (multiple times).
So, for example, let's say that this is my list of these specific nodes:
nodelist = [3 27 38] %(so these are my node ID's)
Then for each node I have the following dataset associated
a (scalar)
b (5x5 double matrix)
c (10x1 double vector)
(a total of 36 double values associated with each node ID)
In reality, I will of course have a much, much longer list of node ID's and a somewhat larger data set associated with each node (but still only double scalars, matrices and vectors (no characters, strings etc)).
Approach 1
So one approach I cooked up is just to store everything in a 2D double matrix, and then do some relatively complex indexing to access my data when needed. For the example above, the size of my 2D matrix would be
size(2Dmat) = [length(nodelist), 36]
Say I wanted to access b(3,3) for node ID 27, I would access 2Dmat(2,14).
In principle, this works, but the code is just not very clean and readable because of this complex indexing (not to mention, when I change something in the way the data set is set up, I need to re-adjust the whole indexing code).
Approach 2
Another approach would be to use some sort of struct for each node in the node list:
a = 4.4;
b = rand(5,5);
c = rand(10,1);
s = struct('a',a,'b',b,'c',c)
And then I can access the data via, e.g., s.b(3,3) etc. But I just don't know how to associate a struct with the node ID?
Approach 3
The last thing I could think of would be to set up some sort of SQL database, but this seems like an overkill. And besides, I need my code to be as fast as possible, since I need to access these fields in the datasets associated with these chosen nodes many, many times and I imagine doing some queries into a database will slow things down.
Note that ultimately I will convert the code from Matlab to C/C++, so I would prefer to implement something that doesn't rely to heavily on some Matlab specific features.
So, any thoughts on how to implement this functionality in a clean way? I hope my question makes sense and thanks in advance!