MATLAB: Error using detrend. Too many output arguments

detrendtoo many output arguments

I would like to run this function.
[dataL_d,Tr] = detrend(dataL,1);
However, the following error always occurs:
Error using detrend. Too many output arguments.
I need the Tr information. If I do not want to output Tr, it works. See command below.
[dataL_d] = detrend(dataL,1);
I would be very happy about an answer.
Best regards,
Christoph

Best Answer

You are asking detrend to remove a linear trend.
To get the slope and intercept of your data, use the polyfit function. There is no specified independent variable value, so use the index vector for that:
P = polyfit((1:numel(dataL)), dataL, 1)
The slope is ‘P(1)’ and the intercept is ‘P(2)’.