Time vector

9 次查看(过去 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