簡體   English   中英

歸一化3d直方圖,因此在Matlab中曲線下的總和= 1

[英]Normalize 3d histogram so the sum under the curve = 1 in Matlab

我需要了解如何對已歸一化的數據進行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之間。我無法發布圖像。

嘗試使用此代碼,如果將垃圾箱均等放置,則可能會得到滿意的結果。

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM