How do i omit NaN values from polyfit?
Afficher commentaires plus anciens
I am pulling data from an excel sheet that has empty cells in it which appear as NaNs. I am plotting the data in this excel file, and i want a best fit line to go through it. If i try to use the polyfit function, it returns NaN values because of the empty cells in the excel sheet. Is there anyway i can have the sheet omit the NaN values and only look at the cells with data in them?
filename = 'NB-Aroostook.xls';
numData = xlsread(filename);
[rows, columns] = size(numData);
x=(1:rows);
length= x.';
maxt=numData(1:rows,3);
figure(1)
hold on;
plot(length, maxt, 'LineWidth', .2);
pbaspect([3 1 1]);
fit1=polyfit(length,maxt,1);
plot(length,fit1,'Color','k');
xlabel('Year');
ylabel('Maximum Monthly Temperature (°C)');
Any help is appreciated!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!