function [Rho, Pv, ll, tt]=correlplot(Xmat,dot_col,xlims,ylims) if nargin <4 ylims=[]; if nargin<3 xlims=[]; if nargin<2 dot_col=[0 0 0]; end end end if size(Xmat,2)==2 && size(Xmat,1)==2 Xmat=Xmat'; elseif all(size(Xmat)~=2) error('The input matrix has to be of size 2 along at least one dimension'); end [Rho,Pv] = corrcoef(Xmat); plot(Xmat(:,1), Xmat(:,2),'o','color',dot_col,'markerfacecolor',dot_col,'markersize',.5); hold on %[ zq, xq ] = nanmeanquantized( [-.005:.01:1.005], Xmat(:,1), Xmat(:,2) ); %plot(xq,xq,'o','color',dot_col,'markerfacecolor',dot_col,'markersize',2); hold on if isempty(ylims) || isempty(xlims) if all(Xmat>0) ylim([ 0 1].*max(abs(Xmat(:)))); xlim([ 0 1].*max(abs(Xmat(:)))); else ylim([-1 1].*max(abs(Xmat(:)))); xlim([-1 1].*max(abs(Xmat(:)))); end else ylim(ylims); xlim(xlims); end ll=lsline(); gch=gca; daspect([1 1 1]); tt=text(mean(gch.XLim),max(gch.YLim).*.85,[sprintf('\\rho=%2.2f',Rho(1,2)) getpstars(Pv(1,2))]); if Pv(1,2)<0.05 if Rho(1,2)<0 ll.Color=[1 0 0]; tt.Color=[1 0 0]; else ll.Color=[0 0 1]; tt.Color=[0 0 1]; end end if isempty(ylims) || isempty(xlims) if all(Xmat>0) ylim([ 0 1].*max(abs(Xmat(:)))); xlim([ 0 1].*max(abs(Xmat(:)))); else ylim([-1 1].*max(abs(Xmat(:)))); xlim([-1 1].*max(abs(Xmat(:)))); end else ylim(ylims); xlim(xlims); end end