How to convert continuous form of data into discrete steps form?
Mostrar comentarios más antiguos
I looking for help to convert countinous form of data into discreate steps form.
Here is the example, please help me to ffind solution.
X = [ 1 3 5 8 10 15 20 25 30 34 38 40 45 50 55 60 65 69 70]
y =[ 1 3 5 4 6 5 8 7 6 7 6 7 6 7 6 7 5 7 0 1]
I want convert X variable in to steps multiple of 5 [0 5 10 15 20 25..] and coresspong values of y betwen these steps should be mean(y). Well I am looking for output in the following format.
x= [5,10,15...]
y=[3,5,5..].
I tried with find(x<5), which gave me indices for calculating the mean (y), but its too laborous method.
Thank you
10 comentarios
Cris LaPierre
el 22 de Ag. de 2020
Given what you've specificed, how does y=8 when x=5?
Chetan Badgujar
el 22 de Ag. de 2020
Cris LaPierre
el 23 de Ag. de 2020
Editada: Cris LaPierre
el 24 de Ag. de 2020
You can use groupsummary.
x = [ 1 3 5 8 10 15 20 25 30 34 38 40 45 50 55 60 65 69 70]';
y =[ 1 3 5 4 6 5 8 7 6 7 6 7 6 7 6 7 5 7 0]';
% Define edges of ranges
rg = 0:5:100;
% Identify groups (
G = discretize(x,rg,"IncludedEdge","right");
% Find the max value in each range
Y = groupsummary(y,x,rg,@mean,"IncludedEdge","right")
X = rg(unique(G+1)) % G+1 is to get the result you show
Chetan Badgujar
el 23 de Ag. de 2020
Cris LaPierre
el 23 de Ag. de 2020
Editada: Cris LaPierre
el 23 de Ag. de 2020
Sorry, I switched from splitapply to groupsummary and removed the line that creates G. I've updated the code. Try it now. If you are still getting an error message, please share the complete error message. It might also be helpful if you could share you actual data.
Chetan Badgujar
el 24 de Ag. de 2020
the cyclist
el 24 de Ag. de 2020
One minor point: I recommend against using rng as a variable name, since it is also MATLAB function name.
Cris LaPierre
el 24 de Ag. de 2020
Editada: Cris LaPierre
el 24 de Ag. de 2020
Why create a new question asking the same thing?
@the cyclist - good point. I renamed the variable to rg.
Chetan Badgujar
el 24 de Ag. de 2020
Adam Danz
el 24 de Ag. de 2020
You can flexibly compute the edges using
rg = 0:5:ceil(X/5)*5;
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Tables 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!
