Aplly average to a set of data

1 Ansicht (letzte 30 Tage)
Angel Lozada
Angel Lozada am 19 Jun. 2023
Kommentiert: Star Strider am 20 Jun. 2023
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])

Akzeptierte Antwort

Star Strider
Star Strider am 19 Jun. 2023
Bearbeitet: Star Strider am 19 Jun. 2023
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 Kommentare
Angel Lozada
Angel Lozada am 20 Jun. 2023
Star Strider.
I really appreciate your collaboration.
Regards.
Star Strider
Star Strider am 20 Jun. 2023
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by