how to generate absolute difference between two different histograms
Mostrar comentarios más antiguos
I have two histograms .i need to find absolute difference between those two histograms and generate histogram for that absolute difference.
Respuestas (3)
KALYAN ACHARJYA
el 28 de Ag. de 2019
Editada: KALYAN ACHARJYA
el 28 de Ag. de 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 comentarios
Aashmi S
el 28 de Ag. de 2019
KALYAN ACHARJYA
el 28 de Ag. de 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);
Steven Lord
el 28 de Ag. de 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
el 29 de Ag. de 2019
0 votos
Categorías
Más información sobre Data Distribution Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!