Aplly average to a set of data

1 回表示 (過去 30 日間)
Angel Lozada
Angel Lozada 2023 年 6 月 19 日
コメント済み: Star Strider 2023 年 6 月 20 日
Hello
I will really appreciate your help regarding follow code.
As it can see, x axis is measured in second, each second has 10 numbers or data samples (do a zoom in, to see a specific second).
I am trying to apply movmean function in order to obtain one (1) number as result of the average of each ten numbers per second (see attached file Figure 2 for reference).
Regards.
clear;
Uzp = unzip('Data 2.zip');
data = readmatrix('Data 2');
t = seconds(data(:,1));
ixv = ceil(data(:,1) + 1E-12);
secv = accumarray(ixv, (1:size(data,1)).', [], @(x){data(x,[2 3])});
A2 = reshape(cell2mat(secv).', 2,10,[]);
tv = unique(ixv);
figure
plot(tv, squeeze(A2(1,:,tv)), '.')
ylabel('Phase (°)')
grid
xlabel('Time')
xlim([tv(1) tv(end)])
xlim([0 86400])

採用された回答

Star Strider
Star Strider 2023 年 6 月 19 日
編集済み: Star Strider 2023 年 6 月 19 日
This seems to be a slightly different version of your earlier Question: Plot data from txt file.
This does the same thing,, except that instead of returning a cell array of the individual points, it takes the mean of each interval and returns it —
clear;
Uzp = unzip('Data 2.zip');
data = readmatrix('Data 2');
t = seconds(data(:,1));
ixv = ceil(data(:,1) + 1E-12);
secv = accumarray(ixv, (1:size(data,1)).', [], @(x){mean(data(x,[2 3]))});
secm = cell2mat(secv); % Create Matrix From Cell Array
% A2 = reshape(cell2mat(secv).', 2,10,[]); % Not Needed Here
tv = unique(ixv);
figure
plot(tv, secm, '-')
ylabel('Phase (°)')
grid
xlabel('Time')
xlim([tv(1) tv(end)])
xlim([0 86400])
figure
plot(tv, secm, '-')
ylabel('Phase (°)')
grid
xlabel('Time')
xlim([tv(1) tv(end)])
xlim([0 1E+2])
figure
stairs(tv, secm)
ylabel('Phase (°)')
grid
xlabel('Time')
xlim([tv(1) tv(end)])
xlim([0 1E+2])
The difference here is that movmean creates a moving average of adjacent elements. This code creates the mean of consecutive 10-element segments of the signal, so not a moving average and instead so sort of average of adjacent 10-element blocks of the data.
NOTE — The ‘secm’ matrix has a row length that is 1/10 the length of ‘data’. So it does what you want it to do.
EDIT — Re-ran code.
.
  2 件のコメント
Angel Lozada
Angel Lozada 2023 年 6 月 20 日
Star Strider.
I really appreciate your collaboration.
Regards.
Star Strider
Star Strider 2023 年 6 月 20 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by