Block averaging a large matrix

20 views (last 30 days)
Duncan Wright
Duncan Wright on 14 Nov 2017
Commented: Duncan Wright on 14 Nov 2017
How do I go about block averaging a large matrix?? My structure 'EchoSounder1FBin1_Data' has the fields with the following dimensions:
EchoSounder1FBin1_Data.Echo11000kHzBin1_1000kHz = [7866×14400 single]
EchoSounder1FBin1_Data.Time = [1×14400 single]
EchoSounder1FBin1_Data.Range = [7866×1 single]
I would like to block average the data so I can plot it without it crashing my computer.. eg. reduce the variable size by averaging say over every 50 data points.
Thanks

Accepted Answer

Jan
Jan on 14 Nov 2017
Edited: Jan on 14 Nov 2017
A fast C-Mex would be https://www.mathworks.com/matlabcentral/fileexchange/24812-blockmean, but currently it works with UINT8 and DOUBLEs only. But the M-File will work with a tiny modification:
if isa(X, 'double') ==> if isfloat(X)
In short it does:
X = EchoSounder1FBin1_Data.Echo11000kHzBin1_1000kHz;
S = size(X);
X = reshape(X, 50, S(1)/50, 50, S(2)/50);
Y = sum(sum(X, 1), 3) .* (1.0 / 2500); % Slightly faster than / 2500
Y = reshape(Y, S(1)/50, S(2)/50);
By the way: "Echo11000kHzBin1_1000kHz" means, that you store important data describing the measurement in the name of the variable. This is a bad design, because it impedes the automatic processing. Prefer to store the details of a measurement accessible in fields:
Data(1).Echo.Frequency = 11000;
Data(1).Echo.Bin = 1;
Data(1).Echo.Width = 1000;
Data(1).Echo.Signal = ...
Then it is much easier to apply a processing for a certain subset of data without complicated string parsing of the field names.

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices 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!