book_3_49.m

Plot group mean values with trend line.

load fly

uniqueTemp = unique(Temperature);
nT = length(uniqueTemp);
meanFacet = nan(nT,1);

for ii = 1:nT
   index = Temperature==uniqueTemp(ii);
   meanFacet(ii) = mean(FacetNumber(index));
end

% Compute a trend line through the mean values.
p = polyfit(uniqueTemp(:),meanFacet(:),1);
fitTemp = linspace(min(uniqueTemp),max(uniqueTemp),50);
fitFacet = polyval(p,fitTemp);

plot(uniqueTemp,meanFacet,'o',fitTemp,fitFacet,'-')
xlabel('Temperature (deg C)')
ylabel('Facet Number')
title('Fly')