how to generate absolute difference between two different histograms
이전 댓글 표시
I have two histograms .i need to find absolute difference between those two histograms and generate histogram for that absolute difference.
답변 (3개)
KALYAN ACHARJYA
2019년 8월 28일
편집: KALYAN ACHARJYA
2019년 8월 28일
data1=randi(100,1,100); % Just an example
data2=randi(100,1,100); % Just an example
diff=abs(hist(data1)-hist(data2));
result=hist(diff);
댓글 수: 2
Aashmi S
2019년 8월 28일
KALYAN ACHARJYA
2019년 8월 28일
Have you tried this code?
data1=randi(100,1,100); % Just an example
data2=randi(100,1,100); % Just an example
diff=abs(hist(data1)-hist(data2));
result=hist(diff);
Steven Lord
2019년 8월 28일
Let's create some sample data and a collection of edges that should span the data.
x1 = randn(1, 1e3);
x2 = randn(1, 1e3) + 0.25;
E = -5:0.25:5;
Show the first two histogram objects on separate axes with the same limits. If you don't need the individual histogram objects, call histcounts instead and use the output from those calls instead of the BinCounts properties of the histogram objects in the next step.
subplot(3, 1, 1)
h1 = histogram(x1, E);
subplot(3, 1, 2)
h2 = histogram(x2, E);
% Set the limits of the two axes containing each histogram to be the same
% First get the axes handles
ax1 = ancestor(h1, 'axes');
ax2 = ancestor(h2, 'axes');
% Set the X limits for both axes to be [-5 5] since that's the limit of our edges
xlim(ax1, [-5 5]);
xlim(ax2, [-5 5]);
% Get the Y limits of each axes
y1 = ylim(ax1);
y2 = ylim(ax2);
% The lower Y limit of each axes should be 0.
% The upper Y limit should be the greater of the two that histogram chose
% based on the largest BinCount
consistentYlimits = [0, max(y1(2), y2(2))];
ylim(ax1, consistentYlimits);
ylim(ax2, consistentYlimits);
Now we'll show the absolute difference histogram.
absdiff = abs(h1.BinCounts - h2.BinCounts);
subplot(3, 1, 3);
h3 = histogram('BinCounts', absdiff, 'BinEdges', E);
% Set the limits of the third axes to be the same as those of the first two axes
ax3 = ancestor(h3, 'axes');
xlim(ax3, [-5 5])
ylim(ax3, consistentYlimits);
카테고리
도움말 센터 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!