How do i omit NaN values from polyfit?
이전 댓글 표시
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!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!