How do I average data to produce 1-m interval bins?
Show older comments
I've got arrays (from text files) of profiles, 1 -> 200m, and back up to the surface, with 40 variables (columns). The data are acquired continuously over depth. I'm looking for a routine that will give me depths at 1-m intervals across all 40 columns, so I end up with arrays of (1:200,1:40). An additional problem is that the profiles vary slightly in near-surface and bottom depths (e.g., 3-197, 2-198, etc), making it a challenge to create arrays of depth v. some variable across all profiles for contouring purposes.
7 Comments
Star Strider
on 15 Jul 2015
This is obviously dependent on your file, not something any of us can guess. Attach it or a representative sample from it, including any header lines and such. (Use the ‘paperclip’ icon to attach the file.)
John
on 15 Jul 2015
Star Strider
on 15 Jul 2015
No file yet. There are two steps: ‘Choose file’ and then click ‘Attach file’ over on the lower-right of the ‘Attach a <file:’> window.
John
on 15 Jul 2015
Star Strider
on 15 Jul 2015
Edited: Star Strider
on 15 Jul 2015
No worries. It’s on partially visible in the window on my browser, so it’s not easy to find. I just have experience with Answers, so I know to look for it.
EDIT — Which column is depth? Is Column A just a counter, or does it have other significance?
When I read it with xlsread, it’s a (36x19) double array. (I don’t have 40 columns, but that may not be important.)
John
on 16 Jul 2015
Star Strider
on 16 Jul 2015
That shouldn’t affect my code. I changed it to account for the depth in Col #18, although it ended up in Col 17 in the output of my code, since I deleted Col #1 (a line counter) in the output. You can always put the depth in any column you want. Just change the other column assignments.
If somehow it does affect my code, post a section of your complete data set and I will change my code to accommodate your full-column data file.
Accepted Answer
More Answers (1)
Guillaume
on 15 Jul 2015
Assuming that each row of your array is of the form:
%depth var1 var2 ... var40
%e.g:
data = [1.1 rand(1,40); %depth is 1.1
2.5 rand(1,40); %depth is 2.5
1.8 rand(1,40); %depth is 1.8
...
]
depths = 1:200
bins = discretize(data(:, 1), depths);
You can then use a for loop to average for each bin:
newdata = zeros(200, 40);
for depth = depths
newdata(depth, :) = mean(data(bins == depth, 2:41));
end
Categories
Find more on File Operations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!