I would like to use splitapply with polyfit as the input function on a dataset to generate the first order polynomials per group but cannot get the hang of what to put on the left side to generate the correct output.
I've generated the grouping variable G for my groups and made a vector f_ones at the same length as the data set to use as input for the order. My code trials have been variants of this with the following error message.
a1 = splitapply(@polyfit,T.x, T.y, f_ones, G);
Error using splitapply (line 132)
Applying the function 'polyfit' to the 1st group of data generated the following error:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
I've tried with a1 undeclared and declared as a table as well as a variant of [a1 b1] but nothing seems to match the expected output. Can someone help me how to phrase this function properly?