how to generate absolute difference between two different histograms

7 vues (au cours des 30 derniers jours)
Aashmi S
Aashmi S le 28 Août 2019
Réponse apportée : Aashmi S le 29 Août 2019
I have two histograms .i need to find absolute difference between those two histograms and generate histogram for that absolute difference.

Réponses (3)

KALYAN ACHARJYA
KALYAN ACHARJYA le 28 Août 2019
Modifié(e) : KALYAN ACHARJYA le 28 Août 2019
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 commentaires
Aashmi S
Aashmi S le 28 Août 2019
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 le 28 Août 2019
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);

Connectez-vous pour commenter.


Steven Lord
Steven Lord le 28 Août 2019
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 le 29 Août 2019
thanks sir
but this coding doesnt work for the image histograms
its gives an error

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by