How to change X axis to show time based on my start-end and frequency
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I have imported files from excel table into workspace and I can see my data as 1000x1 double. When I try to plot it, it creates a plot with Y-axis showing data from my excel table and X-axis shows some automatic generated numbers from 0-10^4.
Is it possible to change this X-axis to show only minutes and seconds since I know the starting time and end time, and frequency of data is 15Hz ?
Thanks
0 Kommentare
Antworten (1)
Star Strider
am 17 Okt. 2016
2 Kommentare
Star Strider
am 18 Okt. 2016
My pleasure.
It may not be possible to do it at all.
Your sampling frequency is 15 Hz, so your samping interval is 0.0667 seconds (rounded). Your vector has 1000 samples, so your vector is 66.667 seconds long, or just over one minute.
The Code:
Fs = 15; % Sampling Frequency
Ts = 1/Fs; % Sampling Interval
L = 1000; % Vector Length
millisec = linspace(0, L*Ts, L)'; % Milliseconds Vector (Column)
dt1 = datetime(0,0,0,02,45,0,millisec); % ‘datetime’ Call
dt1.Format = 'HH:mm:ss'; % Set Output Format
Please reconcile this with your statement: ‘My start time is 2:45:00 and end time is 3:15:00.’
The Code:
dn = datenum([0 0 0 2 45 0; 0 0 0 3 15 0]); % Set Date Numbers For ‘02:45:00’ To ‘03:15:00’
dnv = dn(1) : 1/(24*60*60) : dn(2); % Fill Vector By Minutes
dt2 = datetime(dnv', 'ConvertFrom','datenum'); % ‘datetime’ Call
dt2.Format = 'HH:mm:ss'; % Set Output Format
This creates the vector you want, however it is (1801x1). If you sampled at 15 Hz over that interval, your vector would have to be (1620900x1)
This is inconsistent.
Siehe auch
Kategorien
Mehr zu Numeric Types finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!