フィルターのクリア

Average of every n values in a matrix.

9 ビュー (過去 30 日間)
Austin Ukpebor
Austin Ukpebor 2021 年 2 月 11 日
コメント済み: Austin Ukpebor 2021 年 2 月 11 日
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);

採用された回答

Mathieu NOE
Mathieu NOE 2021 年 2 月 11 日
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
  1 件のコメント
Austin Ukpebor
Austin Ukpebor 2021 年 2 月 11 日
This worked for me. Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by