我需要了解如何对已归一化的数据进行3d直方图处理,因此面积小于= 1。我有
data=[data_x,data_y];
[HIST,Cent]=hist3(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
它运作良好,但是如何更改归一化直方图上的轴tic,其负值和我的数据应为正值。我的data_x在-180到180(角度)之间,而data_y在0到1之间。我无法发布图像。
尝试使用此代码,如果将垃圾箱平均放置,则可能会得到满意的结果。
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图需要进行一些后期处理:更改轴的刻度,以及更改条形之间的间隙和颜色。我无法发布图片,因此您应该尝试运行代码并检查结果是否可接受。
编辑:或者,您可以使用修改直方图的z轴上的刻度标签V_tot
。
编辑:更改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)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句