MATLAB: How to group data in different size categories

bar categoriescategorygroupgroup data

Hi everyone! So I want to categorize the first column of the follwing data according to: [0;3.5;6;8;10;12;14;16;18;20;22;24;26;28;30;32;36;40]
x y
0 0.0040
17.8200 0.0030
19.0700 0.0035
19.1600 0.0028
19.9300 0.0035
20.3800 0.0208
20.4100 0.0002
20.4800 0.6503
20.5100 0.0043
20.5400 0.1609
20.5700 0.0275
20.6000 0.0023
20.6400 0.0142
20.6700 0.0025
20.7000 0.0255
20.7600 0.0028
20.8300 0.0066
20.8600 0.0032
20.9600 0.0023
21.0800 0.0193
21.1200 0.0098
21.2100 0.0112
21.3100 0.0023
21.3400 0.0012
21.3700 0.0054
21.5000 0.0029
21.6000 15.7993
21.6300 0.0171
21.7600 0.0065
21.7900 0.0034
21.8500 3.9724
21.9500 0.0041
22.2000 0.0116
22.4000 0.0025
22.4300 1.1909
I need that in order to plot the values in bar where x will appear in categories 0-3.5, 3.5-6 etc.
Any help would be appreciated! Thank you very much!

Best Answer

Use the histc function.
I named your array xy and your bin edges binrng:
binrng = [0;3.5;6;8;10;12;14;16;18;20;22;24;26;28;30;32;36;40];
xy = [0 0.0040
17.8200 0.0030
19.0700 0.0035
19.1600 0.0028
19.9300 0.0035
. . . ];
counts = histc(xy(:,1),binrng)