Bin edges of discretize function excluding some bins
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
Respuesta aceptada
Cris LaPierre
el 10 de Ag. de 2020
mtransf(102,:) = discretize(mtransf(101,:),binEgdes,"Categorical",catnames);
mtransf(102,mtransf(102,:)==4)=NaN;
5 comentarios
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Statistics and Machine Learning Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!