How to change X axis to show time based on my start-end and frequency
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Star Strider
el 17 de Oct. de 2016
2 comentarios
Star Strider
el 18 de Oct. de 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.
Ver también
Categorías
Más información sobre Numeric Types en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!