0001 function h = scatter_w_stats(xdata,ydata,params)
0002
0003
0004
0005
0006
0007
0008 if ~all(size(xdata) == size(ydata))
0009 error('xdata and ydata must be the same size')
0010 end
0011
0012 if size(xdata,2) == 1
0013 xdata = xdata(:);
0014 ydata = ydata(:);
0015 end
0016
0017 ncols = size(xdata,2);
0018
0019
0020 for icol = 1:ncols
0021 h(icol) = scatter(xdata(:,icol), ydata(:,icol));
0022 hold 'on'
0023 end
0024
0025
0026 for icol = 1:ncols
0027 [b,~,~,~,stats] = regress(ydata(:,icol),[ones(size(xdata(:,1))) xdata(:,icol)]);
0028
0029 xlims = get(gca,'xlim');
0030 l(icol) = line(xlims,xlims*b(2)+b(1),'Color',get(h(icol),'CData'));
0031
0032 Rsqr = stats(1);
0033 r(icol) = sqrt(Rsqr)*sign(b(2));
0034 p(icol) = stats(3);
0035
0036
0037 if sign(b(2)) > 0
0038 horizontalAlign = 'right';
0039 else
0040 horizontalAlign = 'left';
0041 end
0042 verticalAlign = 'bottom';
0043
0044 t(icol) = text(mean(xlims), mean(xlims)*b(2)+b(1), sprintf('r(%d) = %.2f, p = %.4f', ...
0045 sum(~isnan(ydata(:,icol)))-1, r(icol), p(icol)), ...
0046 'horizontalAlign', horizontalAlign, ...
0047 'verticalAlign', verticalAlign);
0048 end
0049
0050 end