Time vector

조회 수: 8 (최근 30일)
Baba
Baba 2011년 10월 31일
I have 1000 data points and know that they were opbtained with 1Hz sampling. I also have begining time: Begining time = 12:00:00
How would I make a time vector? such that I can plot the data vs time and able to pick out a datapoint and know it's coorespoinding time.
Thank you!

답변 (3개)

Alex
Alex 2011년 10월 31일
Do you want the answer in hh::mm::ss format?
sample_index = (selected sample index);
%elapsed time in seconds
elapsed_time = sample_index*(1/frequency);
%hoping you have start time in seconds and not in a string
time_at_sample = elapsed_time + start_time;
tot_seconds = time_at_sample
%convert to str
hour = fix(tot_seconds / sec_in_hour);
tot_seconds = mod(tot_seconds, sec_in_hour);
min = fix(tot_seconds / sec_in_min);
sec = mod(tot_seconds, sec_in_min);
time_str = sprintf('%i%i%i', hour, min, sec);

the cyclist
the cyclist 2011년 10월 31일
Here's one way:
basetime = [2011 01 01 12 0 0]; % Arbitrary date, starting at noon
basetimeVec = repmat(basetime,[1000 1]);
basetimeVec(:,6) = (0:999)'; % Add one second at a time (because 1 Hz rate)
timevec = datenum(basetimeVec); % MATLAB datenum format
datestr(timevec); % String with the time

Fangjun Jiang
Fangjun Jiang 2011년 10월 31일
StartTime=datenum(2011,10,31,12,00,00);
OneSecond=1/3600/24;
TimeVector=StartTime+OneSecond*(0:1000);
datestr(TimeVector)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by