Linear Regression gives NaN
Mostrar comentarios más antiguos
Hi,
I am trying to do and plot a linear regression for the dataset attached. I tried following examples online, but I am getting NaN. This is my code and my data is attached.
clc
close all
clear all
%% Map
filename = 'TV_NYMA';
[num,string,vt] = xlsread(filename);
Year = num(:,1);
County = string(:,2);
VOC = num(:,3);
NOx = num(:,4);
CO = num(:,5);
PM25 = num(:,6);
Lat = num(:,7);
Lon = num(:,8);
%%
standard_NOx = normalize(NOx);
standard_VOC = normalize(VOC);
figure
scatter(standard_NOx,standard_VOC)
title('NOx vs VOC')
xlabel('NOx emissions standardized')
ylabel('VOC emissions standardized')
%%
X = [ones(length(standard_NOx),1) standard_NOx]
b = X\standard_VOC
regression_line = [ones(size(standard_NOx,1),1) standard_NOx]*b
I was wondering what am I doing wrong.
Thanks.
2 comentarios
dpb
el 20 de Mayo de 2021
I didn't download the data, but why not
b=polyfit(standard_NOx,standard_VOC,1);
yhat=polyval(b,[min(standard_NOX) max(standard_NOX)]);
or, if have one of Statistics or Curve Fitting Toolboxes, there are other higher-level routines as well...
Just out of curiosity, did you look at what was returned for the coefficients matrix? Was it NaN there, already? IF so, there's probaby a NaN in the mix in the data somewhere.
John Ziggs
el 20 de Mayo de 2021
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Linear and Nonlinear Regression en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
