Can anyone teach me how to plot the line of best fit in this graph?
Matlab keeps gving me error message that polymial is not uniquie when i use polyfit() command
THx
% change working directory to data directory
cd C:\weatherdata
number_of_files=length(dir)-3;
for n=3:number_of_files
s=load(['D',num2str(n),'.txt']);
% define y as height data
y = s(11,:);
% define x as temperature data
x = s(16,:);
% find the size of matrix s to define max of j
[rmax cmax]=size(s);
% input no. of columns of data programme will consider
for j= 1:cmax;
% eliminate data that has no height or temperature recorded
if x(1,j) ~= 99
if y(1,j) ~= 99
% convert height in feet to km and plot data points
plot(x(1,j),y(1,j)/3280.8399 ,'r+')
% command to prevent new plots from replacing old plots
P = polyfit(x(1,j),y(1,j),1);
Y = polyval(P,x(1,j));
hold on;
end
end
end
end
%label graph
xlabel('Temperature/°C')
ylabel('Height/km')
title('Graph of Height against Temperature','FontSize',12)
% insert grid
grid on