inpdata = Tower_bins_wind_GF_allyrs;
heights = fieldnames(inpdata);
bins = fieldnames(inpdata.height10m);
names = strtrim(cellstr(num2str([1:length(bins)]'))');
names = strrep(strcat('params',names),'.','');
params = cell(numel(bins),1);
for h = 1:numel(heights);
for i = 1:numel(bins);
inpdata.(heights{h}).(bins{i})(:,3) = log(inpdata.(heights{h}).(bins{i})(:,1));
inpdata.(heights{h}).(bins{i})(:,4) = log(inpdata.(heights{h}).(bins{i})(:,2));
inpdata.(heights{h}).(bins{i}) = inpdata.(heights{h}).(bins{i})(~any(isnan(inpdata.(heights{h}).(bins{i})),2),:);
inpdata.(heights{h}).(bins{i}) = inpdata.(heights{h}).(bins{i})(~any(isinf(inpdata.(heights{h}).(bins{i})),2),:);
if isempty(inpdata.(heights{h}).(bins{i}))
inpdata.(heights{h}) = rmfield(inpdata.(heights{h}),(bins{i}));
else
params{i} = polyfit(inpdata.(heights{h}).(bins{i})(:,3), inpdata.(heights{h}).(bins{i})(:,4), 1);
inpdata.(heights{h}).(bins{i})(:,5) = real(params{i,1}(1,1)*inpdata.(heights{h}).(bins{i})(:,3) + params{i,1}(1,2));
end
[inpdata.(heights{h}).(names{1,i})]= params{i,1};
end
end