# Time vector

8 visualizzazioni (ultimi 30 giorni)
Baba il 31 Ott 2011
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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (3)

Alex il 31 Ott 2011
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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

the cyclist il 31 Ott 2011
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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Fangjun Jiang il 31 Ott 2011
StartTime=datenum(2011,10,31,12,00,00);
OneSecond=1/3600/24;
TimeVector=StartTime+OneSecond*(0:1000);
datestr(TimeVector)
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Logical in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by