How to calculate average time over a given period?

21 visualizaciones (últimos 30 días)
Cameron Spooner
Cameron Spooner el 4 de Jul. de 2016
Respondida: Robert el 6 de Jul. de 2016
My time data (Time) is set up as a cell string with format dd/mm/yy HH:MM:SS. Currently I am filtering the data by a given step (Step) and have a script set up so that the time value at the end of that period will display. The script I am using for that is;
FilteredTime=Time(Step:Step:length(Time));
How do I need to change it so that the average time (or midpoint in time) over this defined step is output rather than the end time?

Respuestas (1)

Robert
Robert el 6 de Jul. de 2016
You could
  1. convert your times to numeric values using datenum
  2. trim your times to an even multiple of step
  3. reshape the array of times to have step rows
  4. average across the rows
Time = cumsum(randi(25,101,1)); % dummy values for the example
step = 5;
% We will take the average of every set of 5 and will ignore the last point
% since it doesn't belong to any set of 5.
Time = Time(1:floor(end/step)*step);
% A compact way to take the average of every set
avg = mean(reshape(Time,step,[]));
% Let's take a look!
plot(1:length(Time),Time,step/2:step:length(Time),avg,'o-')

Categorías

Más información sobre Matched Filter and Ambiguity Function en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by