Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

how do i get the higher values into the bins

1 visualización (últimos 30 días)
johnson saldanha
johnson saldanha el 20 de Nov. de 2018
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
edges=0:10:103
[~, discrete_x] = histc(x, edges);
discrete_x(discrete_x == length(edges)) = length(edges)-1;
discrete_x(discrete_x == 0) = NaN;
in this code the values above 100 is taken as NaN but i want them to go into the 11th bin. how can i do that

Respuestas (2)

GT
GT el 20 de Nov. de 2018
Maybe try using histcounts
Here is a small example:
X = randn(1000,1);
edges = [-5 -4 -2 -1 -0.5 0 0.5 1 2 4 5];
N = histcounts(X,edges)
Where in your example you can specify the edges that you would like.
  3 comentarios
GT
GT el 20 de Nov. de 2018
Which version of MATLAB do you have?
histcounts came out in R2014b
X= 1:10
X(4) = nan
Y = categorical(X,[1:10 nan])
[a,b] = histcounts(Y)
I believe gives the code that you are looking for, or do you absolutely need to use the histc?
johnson saldanha
johnson saldanha el 20 de Nov. de 2018
im using 2013

Bruno Luong
Bruno Luong el 20 de Nov. de 2018
[~, discrete_x] = histc(x, [edges Inf]);
  1 comentario
GT
GT el 20 de Nov. de 2018
Yes, indeed this is a more elegant solution if there are no NaNs. I think I misunderstood the question, @Bruno thanks for stepping in.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by