归一化3d直方图,使得Matlab中曲线下的和= 1

时间:2014-11-03 21:52:31

标签: matlab 3d histogram2d

我需要了解如何制作已经规范化的数据的3d直方图,因此面积小于1。 我有

data=[data_x,data_y];
[HIST,Cent]=hist3(data];

我已阅读过帖子:

MatLab: Create 3D Histogram from sampled data

但我仍然无法理解这种方法。任何专家都可以帮助解释如何在Matlab中完成它吗?

编辑:

我使用了以下代码:

load('of.mat')
data=[single(theta(:)),mag(:)];
%define the x and y axis
edges{1} = -180:90:180;
edges{2} = 0:0.2:1;
hist3(data, 'Edges',edges);
[N,C]  = hist3(data, 'Edges',edges);
x_diff = diff(edges{1});
y_diff = diff(edges{2});
x = repmat([x_diff, x_diff(end)], length(edges{2}),1)';
y = repmat([y_diff, y_diff(end)], length(edges{1}),1);
% volume of the histogram
V_tot  = sum(sum(x.*y.*N));
N_norm = N/V_tot;
figure
% plot normalized histogram
bar3(-C{2}, N_norm');
axis normal

效果很好,但是如何更改标准化直方图上的轴抽搐,其负数和我的数据应为正数。我的data_x介于-180和180(角度)之间,data_y介于0和1之间。我无法发布图像。

1 个答案:

答案 0 :(得分:0)

尝试使用此代码,如果放置的箱子相同,这可能会给您带来满意的结果。

data = mvnrnd([0, 0], eye(2), 10e4);

%define the x and y axis
edges{1} = -4:0.5:4;
edges{2} = -4:0.2:4;

hist3(data, 'Edges', edges);

[N,C]  = hist3(data, 'Edges', edges);

x_diff = diff(edges{1});
y_diff = diff(edges{2});
x = repmat([x_diff, x_diff(end)], length(edges{2}),1)';
y = repmat([y_diff, y_diff(end)], length(edges{1}),1);

% volume of the histogram
V_tot  = sum(sum(x.*y.*N));

N_norm = N/V_tot;

figure
% plot normalized histogram
bar3(-C{2}, N_norm');
axis normal

请注意,bar3图需要进行一些后处理:更改轴的刻度,可能还有条形和颜色之间的间隙。 我无法发布图片,因此您应该尝试运行代码并检查结果是否可以接受。

编辑:或者您可以使用V_tot修改直方图z轴上的刻度标签。

编辑:更改z轴的刻度标签(无bar3图):

data = mvnrnd([0, 0], eye(2), 10e4);

%define the x and y axis
edges{1} = -4:0.5:4;
edges{2} = -4:0.2:4;

hist3(data, 'Edges', edges);

[N,C]  = hist3(data, 'Edges', edges);

x_diff = diff(edges{1});
y_diff = diff(edges{2});
x = repmat([x_diff, x_diff(end)], length(edges{2}),1)';
y = repmat([y_diff, y_diff(end)], length(edges{1}),1);

% volume of the histogram
V_tot  = sum(sum(x.*y.*N));

% change the Z tick labels
z_tval = get(gca, 'ZTick');
z_norm_tval = z_tval/V_tot;
set(gca, 'ZTickLabel', z_norm_tval)