how to generate absolute difference between two different histograms

8 次查看(过去 30 天)
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 个评论
Aashmi S
Aashmi S 2019-8-28
i got the error
Attempt to execute SCRIPT hist as a function:
Error in code (line 45)
diff=abs(hist(data1)- hist(data2));
>>
KALYAN ACHARJYA
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
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);

Aashmi S
Aashmi S 2019-8-29
thanks sir
but this coding doesnt work for the image histograms
its gives an error

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by