In a classification problem, I have c
classes of data, each with e
examples of this data, and each example is represented by a feature vector of length
The restriction with a 3D matrix is that dimensions must have a fixed length (so all classes would have to have the same number of examples, and features).
Assuming that you want a general answer, and providing you want to avoid cell arrays, you could use a structure array:
c(3).name = 'cls3'; %// name of 3rd class
c(3).example(1).name = 'c3e1'; %// name of 1st example of 3rd class
c(3).example(1).data = [1 2 3 4]; %// not sure what is your data structure here
c(3).example(1).features_ID = [101 102]; %// ID of features
c(3).example(2).name = 'c3e2';
c(3).example(2).data = [1 2 3 4 5 6];
c(3).example(2).features_ID = [101 102 103];
I only filled in the 3rd class, with 2 examples, but you get the idea.
Generally it's best to place the longest vector in a column. Therefore, (f, e, c)
should be better than (c, e, f)
, assuming that f
is indeed the longest dimension.
MATLAB is most efficient when working in columns, and many built-in functions are coded to work columnwise by default.
Source: http://www.mathworks.com/help/images/using-columnwise-processing-to-speed-up-sliding-neighborhood-or-distinct-block-operations.html.