필터 지우기
필터 지우기

How to calculate average time over a given period?

조회 수: 23 (최근 30일)
Cameron Spooner
Cameron Spooner 2016년 7월 4일
답변: Robert 2016년 7월 6일
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?

답변 (1개)

Robert
Robert 2016년 7월 6일
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-')

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by