1

我需要了解如何制作我已标准化的数据的 3d 直方图,因此 = 1 下的区域。我有

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

我已阅读以下帖子:

MatLab:从采样数据创建 3D 直方图

但是我仍然无法理解该方法。任何专家都可以帮助解释如何在 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 之间。我无法发布图像。

4

1 回答 1

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 图需要一些后处理:更改轴的刻度,可能还有条形之间的间隙和颜色。我无法发布图像,因此您应该尝试运行代码并检查结果是否可以接受。

编辑:或者您可以使用修改直方图 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)
于 2014-11-04T00:13:39.933 回答