JOINTDIST Usage: [P bins] = JointDist(x,y,nbins) This function calculates the joint distribution of the variables x and y. It is simply a normalized histogram using hist3. nbins can take any form of bins that hist3 can take, but no other hist3 options.
0001 function [P bins] = JointDist(x,y,nbins) 0002 0003 %JOINTDIST 0004 % Usage: [P bins] = JointDist(x,y,nbins) 0005 % 0006 %This function calculates the joint distribution of the variables x and y. 0007 %It is simply a normalized histogram using hist3. nbins can take any form 0008 %of bins that hist3 can take, but no other hist3 options. 0009 0010 %Written by Dan Valente 0011 %October 2007 0012 0013 %ensure x and y are both column matrices 0014 [nrowsx,ncolsx] = size(x); 0015 if (ncolsx ~= 1) 0016 x = x'; 0017 end 0018 [nrowsy,ncolsy] = size(y); 0019 if (ncolsy ~= 1) 0020 y = y'; 0021 end 0022 0023 0024 [H bins] = hist3([x y], nbins); 0025 N = sum(sum(H)); 0026 binsize_x = bins{1}(3)-bins{1}(2); 0027 binsize_y = bins{2}(3)-bins{2}(2); 0028 P = H./(N*binsize_x*binsize_y); %Normalize correctly 0029 0030 0031 return; 0032