in Matlab I have several records of a database stored in the matrix DataMatrix
. Each row of the matrix is a record and each column is the value of a property of the record.
To make the program easy to understand for each column of DataMatrix
I defined a variable name explaining what property is associated to the column, that is:
ColApple = 1;
ColOrange = 2;
ColLemon = 3;
...
I have about 50
columns to name.
My problem is that the values in DataMatrix
are used in different functions and I would like to always use the columns name to work on the data in DataMatrix
. So I have to share between different functions the values of ColApple
, ColOrange
, ColLemon
, ...
Up to now I thought to two possible approaches:
Making the columns name global
Define a function returning the values for the columns name, that is:
[ColApple, ColOrange, ColLemon, ... ] = getColNames
I would avoid the global solution because I think it is dangerous and also because I would like the columns name constant if possible.
The second approach is better but since I have 50
columns I do not know if it is a good idea to have a function returning 50
different values (also it is difficult to maintain in my opinion).
Anyone has a more robust or maintainable approach to solve this problem? I am sure I am not the first one to deal with this but I was not able to find a solution.