Effacer les filtres
Effacer les filtres

what toolbox to include for regression

4 vues (au cours des 30 derniers jours)
Niranjan P K
Niranjan P K le 11 Juin 2024
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?

Réponse acceptée

Shivani
Shivani le 11 Juin 2024
Modifié(e) : Shivani le 11 Juin 2024
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:

Plus de réponses (1)

Image Analyst
Image Analyst le 11 Juin 2024
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;

Catégories

En savoir plus sur Linear and Nonlinear Regression dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by