2d histogram binning

조회 수: 1 (최근 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.
Cedric
Cedric 2017년 9월 9일

댓글을 달려면 로그인하십시오.

카테고리

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