plot shifting while using histcounts

Hi,
I'm trying to compare 2 spectrums but I get this shifting in the X-axis (the blue spectrum is processed data out the red one), my suspition is that it happened since I'm using histocounts.
this is the plot script:
[X,~] = histcounts(X_table.energy,2744);
semilogy(X,'r')
% xlim([1 2000])
hold on
[Z,~] = histcounts(Y,2744);
semilogy(Z,'b')
% xlim([1 2000])

 Respuesta aceptada

Rik
Rik el 16 de Mzo. de 2020

0 votos

You are specifying the number of bins, not the exact bins. Then when you are plotting you don't specify the x-value. If you change either of these the data should align again.

4 comentarios

sani
sani el 16 de Mzo. de 2020
Hi Rik, thanks for your answer.
I didn't quite understand what you mean by exact bins, can you give an example?
Rik
Rik el 16 de Mzo. de 2020
Did you read the documentation for the histcounts function? You can either provide the number of bins, or the edges of those bins. If you use the code below, you re-use the same bin edges for both calls.
[X,edges] = histcounts(X_table.energy,2744);
Z = histcounts(Y,edges);
bincenters=edges(2:end)-0.5*diff(edges(1:2));
semilogy(bincenters,X,'r')
hold on
semilogy(bincenters,Z,'b')
sani
sani el 16 de Mzo. de 2020
thanks a lot!
I did read the documentation but didn't understand the that I need to use edges.
Rik
Rik el 16 de Mzo. de 2020
Well, you don't need to, but if you want to compare two sets of data you should be using the same bins, so you can't let Matlab figure out the bins automatically.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Distribution Plots en Centro de ayuda y File Exchange.

Preguntada:

el 16 de Mzo. de 2020

Comentada:

Rik
el 16 de Mzo. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by