How to change X axis to show time based on my start-end and frequency
조회 수: 6 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Star Strider
2016년 10월 17일
댓글 수: 2
Star Strider
2016년 10월 18일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Numeric Types에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!