How to convert continuous form of data into discrete steps form?
古いコメントを表示
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 件のコメント
Cris LaPierre
2020 年 8 月 22 日
Given what you've specificed, how does y=8 when x=5?
Chetan Badgujar
2020 年 8 月 22 日
Cris LaPierre
2020 年 8 月 23 日
編集済み: Cris LaPierre
2020 年 8 月 24 日
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
2020 年 8 月 23 日
Cris LaPierre
2020 年 8 月 23 日
編集済み: Cris LaPierre
2020 年 8 月 23 日
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
2020 年 8 月 24 日
the cyclist
2020 年 8 月 24 日
One minor point: I recommend against using rng as a variable name, since it is also MATLAB function name.
Cris LaPierre
2020 年 8 月 24 日
編集済み: Cris LaPierre
2020 年 8 月 24 日
Why create a new question asking the same thing?
@the cyclist - good point. I renamed the variable to rg.
Chetan Badgujar
2020 年 8 月 24 日
Adam Danz
2020 年 8 月 24 日
You can flexibly compute the edges using
rg = 0:5:ceil(X/5)*5;
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
