MATLAB: Combine doubles and categorical

categoricalcombinedoublematrix

I have three doubles (11318560×1 double) and three categoricals of the same length. How do I combine these into a matrix (of 11318560×6)?

Best Answer

Hi,
The data structure that fits your use case is the MATLAB tables, more about the same can be read here: https://in.mathworks.com/help/matlab/ref/table.html
To give a sample code:
double1 = [1;2;3];
double2 = [3;4;5];
double3 = [5;6;7];
catData1 = {'tag1';'tag2';'tag3'};
catData2 = {'tag3';'tag4';'tag5'};
catData3 = {'tag5';'tag6';'tag7'};
rownames = {'double1';'double2';'double3';'categorical1';...
'categorical2';'categorical3'};
T = table(double1,double2,double3,categorical(catData1),...
categorical(catData2),categorical(catData3),'VariableNames',rownames);
Do refer the 'categorical' function used in the code in this link: https://in.mathworks.com/help/matlab/ref/categorical.html
Abel
Related Question