MATLAB Answers

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

2 ビュー (過去 30 日間)
Emelie Leht
Emelie Leht 2019 年 8 月 5 日
回答済み: Jyotsna Talluri 2019 年 8 月 8 日
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

  0 件のコメント

サインインしてコメントする。

回答 (1 件)

Jyotsna Talluri
Jyotsna Talluri 2019 年 8 月 8 日
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);

  0 件のコメント

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by