2d histogram binning

2 次查看(过去 30 天)
Adrian Szatmari
Adrian Szatmari 2017-9-9
评论: Cedric 2017-9-9
Hi Folks!
I have written the following Matlab code that works. It takes two set of measurements of different dimension for the same points, and builds "rectangle" histograms from it. My goal is to get the array res, where res(i,j1,j2) = the number of measurements for point i in both bin j1 for the first histogram and bin j2 in the second histogram. Voyez plutot:
clear all
nb = 500;
dim1 = 50;
dim2 = 70;
measurement1 = rand(nb,dim1);
measurement2 = rand(nb,dim2);
edges1 = linspace(0,1, 10);
edges2 = linspace(0,1, 6);
res = zeros(nb, length(edges1), length(edges2));
for i = 1:nb
[N1 EDGES1 BIN1] = histcounts(measurement1(i,:), edges1);
[N2 EDGES2 BIN2] = histcounts(measurement2(i,:), edges2);
for j1 = 1:length(edges1)-1
for j2 = 1:length(edges2)-1
res(i,j1,j2) = sum((BIN1 == j1) & (BIN2 == j2));
end
end
end
It is totally unsexy, especially the triple for loop. Could anyone suggest a better way of doing this? Thanks in advance!
  1 个评论
Cedric
Cedric 2017-9-9
It cannot work as written here, because BIN1 and BIN2 don't have the same dimension. And plutôt has a hat ;-)

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2017-9-9
Why not use histogram2()?
  2 个评论
Adrian Szatmari
Adrian Szatmari 2017-9-9
编辑:Adrian Szatmari 2017-9-9
histogram2(), seems to do what I want, however I do not need the figure display. What I need is speed, since I am doing this thousands of times. I opened histogram2(), but did not really understand the underlying code.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by