what toolbox to include for regression

조회 수: 2 (최근 30일)
Niranjan P K
Niranjan P K 2024년 6월 11일
답변: Image Analyst 2024년 6월 11일
I am running the following code on MATLAB Grader
A=[13 16 19 21 24 26 28]
M=[13 20 23 31 36 42 48]
[r,m,b] =regression(A,M)
It is throwing the following error.
"Undefined function 'regression' for input arguments of type 'double'."
What toolbox I need to include to over come this error?

채택된 답변

Shivani
Shivani 2024년 6월 11일
편집: Shivani 2024년 6월 11일
The regression function is a part of the Deep Learning Toolbox. The following links can be used to access the associated MATLAB documentation.
However, please note that it is not recommended to use the 'regression' function. Instead, it is recommended to use the 'fitlm' function from the Statistics and Machine Learning Toolbox to fit a linear regression model. Please access the following links for more information:

추가 답변 (1개)

Image Analyst
Image Analyst 2024년 6월 11일
For these few data points, and for a case like this where the best fit might simply be a line, you can use the build-in polyfit and polyval functions. Here is some code for you:
A=[13 16 19 21 24 26 28];
M=[13 20 23 31 36 42 48];
plot(A, M, 'b.-', 'MarkerSize', 30); % Plot original data in blue.
grid on;
coefficients1 = polyfit(A, M, 1) % Fit a line.
coefficients1 = 1x2
2.2955 -17.7760
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
coefficients2 = polyfit(A, M, 2) % Fit a quadratic.
coefficients2 = 1x3
0.0422 0.5589 -0.9810
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% Place a line along the fitted formula
x = linspace(min(A), max(A), 1000);
% Plot the fitted line.
y1 = polyval(coefficients1, x);
hold on;
plot(x, y1, 'r-', 'LineWidth', 2); % Plot linear fit as a red curve.
% Plot the fitted quadratic.
y2 = polyval(coefficients2, x);
plot(x, y2, 'm-', 'LineWidth', 2); % Plot quadratic fit as a magenta curve.
legend('Original Data', 'Fitted Line', 'Fitted Quadratic', 'Location', 'northwest')
hold off;

카테고리

Help CenterFile Exchange에서 Smoothing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by