2d histogram binning
조회 수: 1 (최근 30일)
이전 댓글 표시
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
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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!