I would like to store multiple tables in one array. In my code below, I am creating two tables T1
and T2
. I want to store these tables into one variable MyArray
.
LastName = {'Sanchez';'Johnson';'Li';'Diaz';'Brown'};
Age = [38;43;38;40;49];
Smoker = logical([1;0;1;0;1]);
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80];
T1 = table(LastName,Age,Smoker);
T2 = table(Height,Weight,BloodPressure);
% The code below does not work
MyArray(1) = T1;
MyArray(2) = T2;
I know I can use a cell array but I would like to know if it is possible to create a table
datatype array in MATLAB.
Because table
already implements ()
indexing, it's not really clear to me how you would expect to index MyArray
. Your example almost looks to me like MyArray = [T1, T2]
.
I'm not sure if it satisfies your needs, but you can have table
objects with table
variables, like this:
T = table(T1, T2);
You can then using indexing as normal, e.g.
T.T1.LastName{2}