Teaching_correlations

%By Owen Churches – July 2014
%Note: This calls the great myginput function by Frederic Moisy available from the File Exchange: http://www.mathworks.com.au/matlabcentral/fileexchange/12770-myginput

clear all
close all

r = .1

figure(‘units’,’normalized’,’outerposition’,[0 0 1 1], ‘MenuBar’, ‘none’)
h1 = text(1.5,9,’At least three data points are needed for a correlation’, ‘FontSize’, 14)

for n = 1:50
axis image
axis([0 10 0 10])
[x,y] = myginput(1, ‘arrow’)
circle(x,y,r)
data(n,:) = [x y]

if size(data,1)>2
delete(h1)
[R,P]=corrcoef(data)
axis image
axis([0 10 0 10])
StatsString = strcat(‘r(‘, num2str((size(data,1)-1)), ‘) = ‘, num2str(R(2)), ‘, p = ‘, num2str(P(2)));
h1 = text(1.5,9,StatsString, ‘FontSize’, 14)

end
end

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s