How to convert continuous form of data into discrete steps form?
Ältere Kommentare anzeigen
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 Kommentare
Cris LaPierre
am 22 Aug. 2020
Given what you've specificed, how does y=8 when x=5?
Chetan Badgujar
am 22 Aug. 2020
Cris LaPierre
am 23 Aug. 2020
Bearbeitet: Cris LaPierre
am 24 Aug. 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
am 23 Aug. 2020
Cris LaPierre
am 23 Aug. 2020
Bearbeitet: Cris LaPierre
am 23 Aug. 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
am 24 Aug. 2020
the cyclist
am 24 Aug. 2020
One minor point: I recommend against using rng as a variable name, since it is also MATLAB function name.
Cris LaPierre
am 24 Aug. 2020
Bearbeitet: Cris LaPierre
am 24 Aug. 2020
Why create a new question asking the same thing?
@the cyclist - good point. I renamed the variable to rg.
Chetan Badgujar
am 24 Aug. 2020
Adam Danz
am 24 Aug. 2020
You can flexibly compute the edges using
rg = 0:5:ceil(X/5)*5;
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Tables finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
