As others have said, it seems to make little sense to create new variables in each timetable, each of which are a column vector of a constant. Maybe you want something like the following.
First, make something like your data:
n = 3;
tt_list = cell(n,1);
for i = 1:3
X = rand(5,1);
Time = datetime(2020,5,i)+days(rand(5,1));
tt_list{i} = timetable(Time,X);
end
Now get the stats for each timetable, and put those in a table that also includes your cell array of timetables:
t = table(tt_list,zeros(n,1),zeros(n,1),zeros(n,1),'VariableNames',["Data" "Mean" "Min" "Max"]);
for i = 1:n
t.Mean(i) = mean(tt_list{i}.X);
t.Min(i) = min(tt_list{i}.X);
t.Max(i) = max(tt_list{i}.X);
end
From that, you end up with
>> t
t =
3×4 table
Data Mean Min Max
_______________ _______ _______ _______
{5×1 timetable} 0.67375 0.4607 0.94475
{5×1 timetable} 0.56289 0.15039 0.9865
{5×1 timetable} 0.52956 0.26661 0.91785
That's the brute force way. As Guillaume suggests, you might find it convenient to put all your timetables in one longer one. The following gets you essentially yhe same table as above.
tt = vertcat(tt_list{:});
tt.Source = repelem(1:n,5)';
fun = @(x) deal(mean(x),min(x),max(x));
t = rowfun(fun,tt,'GroupingVariable','Source','NumOutputs',3, ...
'OutputFormat','table','OutputVariableNames',["Mean" "Min" "Max"])
>> t =
3×5 table
Source GroupCount Mean Min Max
______ __________ _______ _______ _______
1 5 0.67375 0.4607 0.94475
2 5 0.56289 0.15039 0.9865
3 5 0.52956 0.26661 0.91785
I used rowfun; splitapply or groupsummary would also work.
0 Comments
Sign in to comment.