How to convert continuous form of data into discrete steps form?
Mostra commenti meno recenti
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 Commenti
Cris LaPierre
il 22 Ago 2020
Given what you've specificed, how does y=8 when x=5?
Chetan Badgujar
il 22 Ago 2020
Cris LaPierre
il 23 Ago 2020
Modificato: Cris LaPierre
il 24 Ago 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
il 23 Ago 2020
Cris LaPierre
il 23 Ago 2020
Modificato: Cris LaPierre
il 23 Ago 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
il 24 Ago 2020
the cyclist
il 24 Ago 2020
One minor point: I recommend against using rng as a variable name, since it is also MATLAB function name.
Cris LaPierre
il 24 Ago 2020
Modificato: Cris LaPierre
il 24 Ago 2020
Why create a new question asking the same thing?
@the cyclist - good point. I renamed the variable to rg.
Chetan Badgujar
il 24 Ago 2020
Adam Danz
il 24 Ago 2020
You can flexibly compute the edges using
rg = 0:5:ceil(X/5)*5;
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Tables in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
