How to change X axis to show time based on my start-end and frequency

조회 수: 6 (최근 30일)
Jure Djure
Jure Djure 2016년 10월 17일
댓글: Star Strider 2016년 10월 18일
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

답변 (1개)

Star Strider
Star Strider 2016년 10월 17일
If you have R2014b or later, see if the duration function will do what you want.
  댓글 수: 2
Jure Djure
Jure Djure 2016년 10월 18일
Dear Star,
Thank you for your answer but I am unable to do it with duration function as it is instructed in matlab help.
My start time is 2:45:00 and end time is 3:15:00. So i would like to change my x axis to show this time like 2:45:00,2:45:01,2:45:02,2:45:03,2:45:04.........3:15:00.
Reagrds Ivan
Star Strider
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 CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by