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
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

i got the error
Attempt to execute SCRIPT hist as a function:
Error in code (line 45)
diff=abs(hist(data1)- hist(data2));
>>
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);

댓글을 달려면 로그인하십시오.

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);
Aashmi S
Aashmi S 2019년 8월 29일

0 개 추천

thanks sir
but this coding doesnt work for the image histograms
its gives an error

카테고리

도움말 센터File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

질문:

2019년 8월 28일

답변:

2019년 8월 29일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by