Average of every n values in a matrix.

5 visualizaciones (últimos 30 días)
Austin Ukpebor
Austin Ukpebor el 11 de Feb. de 2021
Comentada: Austin Ukpebor el 11 de Feb. de 2021
I have mx6 matrix. I want to take average of every 10 values for each column ( avg of 1-10, 11-20, .....). I tried the code below for nx1 vector and it worked. I need a help for that of 6 columns. Thank you.
A = readmatrix('cleanedData.csv');
n = 10;
s = numel(A);
out = nanmean(reshape( [A(:);nan(mod(-s,n),1)],n,[]));
avg_data = transpose(out);

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 11 de Feb. de 2021
hello
see 2 examples below , without and with overlapping sections
% dummy data
data = rand(320,15);
buffer = 5; % nb of samples for averaging
% zero overlap mean averaging
[m,n] = size(data)
for ci=1:fix(length(data)/ buffer)
start_index = 1+(ci-1)*buffer;
stop_index = min(start_index+ buffer,length(data));
time_index(ci) = round((start_index+stop_index)/2); % time index expressed as sample unit (dt = 1 in this simulation)
avg_data(ci,:) =mean(data(start_index:stop_index,:)); %
end
figure(1),
plot(time_index,avg_data);
% averaging with overlap
shift = 5; % nb of samples for averaging
buffer = 50; % nb of samples for averaging
overlap = buffer-shift
for ci=1:fix((length(data)-buffer)/shift +1)
start_index = 1+(ci-1)*shift;
stop_index = min(start_index+ buffer,length(data));
out_data{ci} =data(start_index:stop_index,:); %
figure(ci),
plot(out_data{ci});
end

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by