What to state on the left side using splitapply and polyfit?

2 Ansichten (letzte 30 Tage)
Emelie Leht
Emelie Leht am 5 Aug. 2019
Beantwortet: Jyotsna Talluri am 8 Aug. 2019
Hi,
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?
BR, Emelie

Antworten (1)

Jyotsna Talluri
Jyotsna Talluri am 8 Aug. 2019
Hi,
The third argument to the polyfit function is order which should be a single variable and not an array.
The arguments in splitapply all should be of same size and hence f_ones ,an array which contains the same values is passed as a third argument to the polyfit function. So
Modify the function handle polyfit such that it takes only one value of f_ones as order argument
func=@(x,y,z){polyfit(x,y,z(1));
a1 = splitapply(@polyfit,T.x, T.y, f_ones, G);

Kategorien

Mehr zu Workspace Variables and MAT-Files finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by