matlab nd array,matlab实现ND数据的直方图

histograms for ND data

histnd Histogram count of ND data with ND bins

histmat = histnd(x, y, ..., xedges, yedges, ...)

Extract ND histogram data containing the number of events

of [x, y, ...] tuples that fall in each bin of the ND-grid defined by

xedges, yedges, .... The edges are passed to histc internally and should

therefore conform to histc's input restrictions: the edge-vectors should

be monotonically non-decreasing.

[histmat, nOOF, OOFidx] = histnd(x, y, ..., xedges, yedges, ...)

If any values are outside of the range of the edges, they are not

counted. The number of those cases and their linear index in the input

data is however returned in the second and third output arguments.

EXAMPLES

events = 1000000;

x1 = sqrt(0.05)*randn(events,1)-0.5; x2 = sqrt(0.05)*randn(events,1)+0.5;

y1 = sqrt(0.05)*randn(events,1)+0.5; y2 = sqrt(0.05)*randn(events,1)-0.5;

x= [x1;x2]; y = [y1;y2];

For linearly spaced edges:

xedges = linspace(-1,1,64); yedges = linspace(-1,1,64);

histmat = histnd(x, y, xedges, yedges);

figure; pcolor(xedges,yedges,histmat'); colorbar ; axis square tight ;

For nonlinearly spaced edges:

xedges_ = logspace(0,log10(3),64)-2; yedges_ = linspace(-1,1,64);

histmat_ = histnd(x, y, xedges_, yedges_);

figure; pcolor(xedges_,yedges_,histmat_'); colorbar ; axis square tight ;

3D data

x = 3.*randn(640000,1);

y = 1.*randn(640000,1);

z = 1.*randn(640000,1);

histmat = histnd(x,y,z,linspace(min(x),max(x),20),linspace(min(y),max(y),20),linspace(min(z),max(z),20));

% make 3D hist, color of points indicates count

[xp,yp,zp] = meshgrid(linspace(min(x),max(x),20),linspace(min(y),max(y),20),linspace(min(z),max(z),20));

% cut away histogram positions where count is 0

qzero = histmat==0;

histmat(qzero) = [];

xp(qzero) = [];

yp(qzero) = [];

zp(qzero) = [];

% draw points

figure;%('Renderer','OpenGL') % might need the openGL renderer to handle so many points

ax = scatter3(xp(:),yp(:),zp(:),'.');

% color them according to count

cdata = histmat(:)./max(histmat);

set(ax,'CData',cdata);

xlabel('X'), ylabel('Y'), zlabel('Z')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值