bin data and sum values
15 次查看(过去 30 天)
显示 更早的评论
Hi everyone! my problem is I have a vector x and a vector of values at those y for example:
x y
0 0.0040
17.8200 0.0030
19.0700 0.0035
19.1600 0.0028
19.9300 2.0036
20.5400 0.1609
20.5700 0.0275
20.6000 0.0023
20.6400 0.0142
20.6700 20.5603
20.9600 0.0023
21.0800 0.0193
21.1200 0.0098
21.2100 31.5333
21.3100 0.0023
21.3400 0.0012
21.3700 0.0054
21.5000 0.0029
21.6000 15.7993
bins = [0;3.5;6;8;10;12;14;16;18;20;22;24;26;28;30;32;36;44;48;50;60];
[counts] = histc(x,bins);
figure=bar(bins,counts,'histc');
That is what I initially did but I also need for each bin to sum the corresponding y values and at the end create a bar graph showing total y for each bin of x. Any ideas??
0 个评论
采纳的回答
Roger Stafford
2014-6-11
[counts,idx] = histc(x,bins);
t = accumarray(idx,y,[size(bins,1),1]);
2 个评论
Rahul Kesarkar
2021-4-7
How would it work if i have to bin data for a particular date range?
For example range : - weekday 12/06/2017 20:00 to 13/06/2017 08:00 and repeat this for every weekday. Weekend 9/06/2017 20:00 to 12/06/2017 08:00. Sum up all the values in the bin.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!