Is there something similar as splitapply that works on a data table instead just on one value?
4 views (last 30 days)
Show older comments
I created a subset of my input data that has more then 400 data sets and called it tex. The Data in each dataset is 13269x3 table, see picture to the right.

I would like to build the maximum for each row of P and QP for all groups of K and L
[perKL,KL,LK] = findgroups(tex.K, tex.L); % The findgroups does its job perferct.
maxByKL = splitapply(@max,tex.Data{:,1}, perKL); % here is the point of question,
Splitapply doesn't work since it expects the same number of rows for the data variable.
Is there already any existing function for that?
0 Comments
Accepted Answer
Matt J
on 14 Feb 2022
Edited: Matt J
on 14 Feb 2022
Tex=varfun(@(x){table2array(x)},tex,'InputVariables','Data');
out = varfun(@(z)max(cell2mat(z)), Tex,'InputVariables','Data','GroupingVariables',{'K','L'})
7 Comments
Matt J
on 15 Feb 2022
Edited: Matt J
on 15 Feb 2022
I think this is what you mean,
Tex=rowfun(@(x){table2array(x)},tex,'InputVar','Data','OutputVar','Data','Extract',1);
Tex=[tex(:,1:2),Tex];
out = varfun(@(z){max(cat(3,z{:}),[],3)}, Tex,'InputVariables','Data','GroupingVariables',{'K','L'});
out(:,3)=[];
out.Properties.VariableNames{3}='maxByKL'
More Answers (0)
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!