Time vector
조회 수: 8 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
답변 (3개)
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);
댓글 수: 0
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
댓글 수: 0
Fangjun Jiang
2011년 10월 31일
StartTime=datenum(2011,10,31,12,00,00);
OneSecond=1/3600/24;
TimeVector=StartTime+OneSecond*(0:1000);
datestr(TimeVector)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!