⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hist2d.m

📁 2D Histrogram Two Dimention Histogram function
💻 M
字号:
% hist2d_hdr ([x,y], xbins, ybins, norm)
% Produce a 2D histogram.
%
% Points xi,yi are stored in a 2-column array.
% If ybins is missing, use xbins.
% If bins is a scalar, use that many bins.
% If bins is a vector, it represents bin edges.

% Author: Paul Kienzle
% This code is public domain.
% Modified by: Henry Douglas Rodrigues

function [x,y,z] = hist2d(M,xbins,ybins)

  if nargin < 1 && nargin > 3, 
      fprintf('[nn,xx] = hist2d (M,x,y)');
  end

  lo = min(M);
  hi = max(M);
  if nargin == 1
    ybins = 10;
    xbins = 10;
  elseif nargin == 2
    ybins = xbins;
  end

  % If n bins, find centers based on n+1 bin edges
  if isscalar(xbins) 
    xbins = linspace(lo(1),hi(1),xbins+1); 
    xbins = (xbins(1:end-1)+xbins(2:end))/2;
  end
  if isscalar(ybins)
    ybins = linspace(lo(2),hi(2),ybins+1); 
    ybins = (ybins(1:end-1)+ybins(2:end))/2;
  end

  xcut = (xbins(1:end-1)+xbins(2:end))/2;
  ycut = (ybins(1:end-1)+ybins(2:end))/2;
  xidx = lookup(xcut,M(:,1))+1;
  yidx = lookup(ycut,M(:,2))+1;
  counts = sparse(xidx,yidx,1,length(xbins),length(ybins));%,'sum');
  
  % Sa韉as
  x = xbins;
  y = ybins;  
  z = (100*full(counts)./sum(sum(counts))).';
  
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -