I would like to compose several arrays into one table. Since they have different data types, it seems not very straightforward. Consider this simple MWE:
daysTotal = 2;
hoursTotal = daysTotal*24;
timeStepHours = 1/4;
nhi = 1/timeStepHours;
q_in_mean = 0.82;
% You may need to change this, according to your locale
startDateTimeStr = '02.09.2019 00:00:00';
startDateTime = datetime(startDateTimeStr);
dateTimeVector = startDateTime:hours(timeStepHours): ...
(startDateTime+days(daysTotal)-hours(timeStepHours));
var1 = ones(hoursTotal*nhi, 3);
var2 = q_in_mean*ones(hoursTotal*nhi, 1);
tableFull = table(dateTimeVector.', var1, var2);
While this works, I get tableFull.var2
in it's old shape, though I would like to have a (hoursTotal*nhi, 5)
table, i.e., one separate table column for each array column.
This would work if all elements were from the same data type:
tableFull = array2table([dateTimeVector.', var1, var2])
And while this works, it does not seem very elegant:
tableFull = horzcat(table(dateTimeVector.'), array2table(var1), table(var2));
Is there a better way to get a (hoursTotal*nhi, 5)
table from those three variables with different data types?