Draw vertical lines which have constant interval
3 ビュー (過去 30 日間)
古いコメントを表示
Hi, I attached time(datetime, 1980.1.1~2015.12.31) and set y value as P=[1:432].
* I convert date form.I also attached original time form(original_time)
time = datetime(original_form,'ConvertFrom','datenum');
If i draw the plot, i got below figure.
plot(time,P);
datetick('x','yy/mm','keeplimits');
grid on
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1143285/image.png)
And i want to add constant vertical line on every March.
I couldn't fine proper method. Please help me :(
採用された回答
VBBV
2022 年 10 月 3 日
編集済み: VBBV
2022 年 10 月 3 日
P=[1:432]
original_form = load('original_time.mat')
time = datetime(original_form.t,'ConvertFrom','datenum')
plot(time,P);
%datetick('x','yy/mm','keeplimits');
grid on
march = time(1) + calmonths(2) : calyears(1) : time(end)
xticks(march)
xline(march,'linestyle','--')
3 件のコメント
VBBV
2022 年 10 月 3 日
編集済み: VBBV
2022 年 10 月 3 日
Following @Walter Roberson answer, you could change the xticks for the plot axis and then draw xline as usual for every march month
VBBV
2022 年 10 月 3 日
編集済み: VBBV
2022 年 10 月 3 日
@Walter Roberson you're right. sorry, i overlooked that line. thanks for it.
その他の回答 (1 件)
Walter Roberson
2022 年 10 月 3 日
編集済み: Walter Roberson
2022 年 10 月 3 日
time = datetime(original_form,'ConvertFrom','datenum');
plot(time, P);
firstmarch = dateshift(time(1), 'start', 'year') + calmonths(2);
lastmarch = dateshift(time(end), 'start', year') + calmonths(2);
marchs = firstmarch : calmonths(12) : lastmarch;
xline(marchs)
参考
カテゴリ
Help Center および File Exchange で Title についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!