Bin edges of discretize function excluding some bins

4 visualizaciones (últimos 30 días)
Filip Simjanoski
Filip Simjanoski el 10 de Ag. de 2020
Editada: Cris LaPierre el 10 de Ag. de 2020
Hello.
mtransf is 100x5000 double where I have some values between -1.3 and 1.3 in each column. I add the mean in row 101 of mtransf:
mtransf(101,:) = mean(mtransf, 1);
I want to discretize the data and make categories in row 102 based on the mean values. With if loops in for loop it works fine but solution is not elegant:
% for i=1:5000
% if (-1.3<=mtransf(101,i)) && (mtransf(101,i)<=(-1.0))
% mtransf(102,i)=1;
% elseif (-1.0<mtransf(101,i)) && (mtransf(101,i)<=(-0.8))
% mtransf(102,i)=2;
% elseif (-0.8<mtransf(101,i)) && (mtransf(101,i)<=(-0.6))
% mtransf(102,i)=3;
% elseif (0.8>=mtransf(101,i)) && (mtransf(101,i)>=0.6)
% mtransf(102,i)=4;
% elseif (1.0>=mtransf(101,i)) && (mtransf(101,i)>0.8)
% mtransf(102,i)=5;
% elseif (1.3>=mtransf(101,i)) && (mtransf(101,i)>1.0)
% mtransf(102,i)=6;
% end
I want to do the same task with discretize, but without the bin between -0.6 and 0.6 :
binEgdes = [-1.3 -1.0 -0.8 -0.6 0.6 0.8 1.0 1.3];
catnames = ["1","2","3","4","5","6","7"];
mtransf(102,:)=discretize(mtransf(101,:),binEgdes,"Categorical",catnames);
Thank you.
  2 comentarios
Cris LaPierre
Cris LaPierre el 10 de Ag. de 2020
How would you categorize the values between -0.6 and 0.6?
Filip Simjanoski
Filip Simjanoski el 10 de Ag. de 2020
There are non existent.

Iniciar sesión para comentar.

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 10 de Ag. de 2020
mtransf(102,:) = discretize(mtransf(101,:),binEgdes,"Categorical",catnames);
mtransf(102,mtransf(102,:)==4)=NaN;
  5 comentarios
Filip Simjanoski
Filip Simjanoski el 10 de Ag. de 2020
Okay this solved my problem. In the end I can still add the categories in my matrix:
dis = discretize(mtransf(101,:),binEgdes,"Categorical",catnames);
dis = removecats(dis,"4");
mtransf(102,:)=dis;
histogram(mtransf(102,:))
Thank you for the fast reply.
Cris LaPierre
Cris LaPierre el 10 de Ag. de 2020
Editada: Cris LaPierre el 10 de Ag. de 2020
That works, but be careful. Your X-axis will be doubles again when you create the histrogram this way, meaning your X-axis is continuous. You will see a bar corresponding to X=4, but corresponds to category "5". Same for X=5 and 6.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Statistics and Machine Learning Toolbox en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by