convert hours to days on y-axis
3 ビュー (過去 30 日間)
古いコメントを表示
Dear all,
I have a file a1, contains two columns, first one is number of segments (each segments represents 12 hours) for one years and seconds columns has data for that segment. I plot the data w.r.t hours.
Is it possible to convert scale from hours to day numbers or date?
here is the example of 6 day data, date started from 10 Oct 2018.
1 0
2 0
3 0
4 0.199999999999996
5 0
6 0
7 0
8 0.199999999999996
9 0
10 0
11 0
12 0
What i want to plot axis w.r.t date, here is the example
10/10/2018 0
0
11/10/2018 0
0.199999999999996
12/10/2018 0
0
Thanks in advance
0 件のコメント
採用された回答
Chunru
2021 年 6 月 23 日
x = [
1 0
2 0
3 0
4 0.199999999999996
5 0
6 0
7 0
8 0.199999999999996
9 0
10 0
11 0
12 0];
bar(datetime('10/10/2018', 'InputFormat', 'dd/MM/yyyy') + hours(x(:,1)*12), x(:,2));
xtickformat('dd/MM/yyyy')
8 件のコメント
その他の回答 (2 件)
KSSV
2021 年 6 月 23 日
A = [1 0
2 0
3 0
4 0.199999999999996
5 0
6 0
7 0
8 0.199999999999996
9 0
10 0
11 0
12 0];
t0 = datetime('10/10/2018') ;
[r,c] = size(A);
N = size(A,1)/2 ; % number of hours in a day
B = permute(reshape(A',[c,r/N,N]),[2,1,3]);
tn = t0+days(N) ;
t = (t0:tn)' ;
Each matrix in B corresponds to respective day in t.
0 件のコメント
Cris LaPierre
2021 年 6 月 23 日
If you convert your data to datetime, then you can set the y axis format to be any valid date format.
data = [1 0
2 0
3 0
4 0.199999999999996
5 0
6 0
7 0
8 0.199999999999996
9 0
10 0
11 0
12 0];
dataTT = array2timetable(data(:,2),'RowTimes',datetime(2018,10,10) + 12*hours(data(:,1)-1))
plot(dataTT.Var1,dataTT.Time)
ytickformat('MM/dd/yyyy')
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!