how can i script for integration/binning at changing lengths? thanks

4 views (last 30 days)
I am analyzing spectral data and am trying to integrate/bin the spectrum between certain limits (bucket widths). Unfortunately, the widths change at unpredictable points, and I was hoping for some help with writing a script that adapts to the bucket widths by integrating data between certain cut-offs (rather than me manually inspecting 46k data points).
For instance, in the below example, the sequence of number of data points is 5, 5, 4 then 5, 5, 5, 4 (then back to 5, 5, 4 and 5, 5, 4 in the original dataset).
bin 0.704 - 0.703 = width of 5 data points
0.70399 114956.75
0.70378 114957.75
0.70356 114958.75
0.70335 114959.75
0.70313 114960.75
bin 0.703 - 0.702 = width of 5 data points
0.70292 114961.75
0.70271 114962.75
0.70249 114963.75
0.70228 114964.75
0.70206 114965.75
bin 0.702 - 0.701 = width of 4 data points
0.70185 114966.75
0.70164 114967.75
0.70142 114968.75
0.70121 114969.75
bin 0.701 - 0.700 = width of 5 data points
0.70099 114970.75
0.70078 114971.75
0.70057 114972.75
0.70035 114973.75
0.70014 114974.75
bin 0.700 - 0.699 = width of 5 data points
0.69992 114975.75
0.69971 114976.75
0.6995 114977.75
0.69928 114978.75
0.69907 114979.75
bin 0.699 - 0.698 = width of 5 data points
0.69885 114980.75
0.69864 114981.75
0.69843 114982.75
0.69821 114983.75
0.698 114984.75
bin 0.698 - 0.697 = width of 4 data points
0.69778 114985.75
0.69757 114986.75
0.69736 114987.75
0.69714 114988.75
I was thinking something along the lines of below, but am not sure where it needs improving. Ideally it would loop through for multiple columns (spectra).
d0=10.5
for binnum=1:46000
dleft(binnum)=d0-(binnum-1)*0.001
dright(binnum)=d0-(binnum-1)*0.001-0.001
end
for i=binint
if d(i)>dright & <=dleft
binint (binnum) = binint (binnum) + int(i)
else
binnum = binnum + 1
binint (binnum) = binint(binnum) + int(i)
bintable(i,:)=binint(binnum)
end
Any help is greatly appreciated!!

Answers (0)

Categories

Find more on Numeric Types in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!