Plotting only the year of a column vector with full date

2 ビュー (過去 30 日間)
Naweed Niaz
Naweed Niaz 2020 年 10 月 21 日
コメント済み: Peter Perkins 2020 年 11 月 19 日
I have a column vector with the dates in the format "MM/dd/yyyy." I would like to plot this against another vector, but only using the year part of the date. How can I extract the yyyy part and assign it to a new vector variable to be able to plot it?
  2 件のコメント
Rik
Rik 2020 年 10 月 21 日
Do you have tyhe dates as a datetime vector, as a string vector, or as a cell vector of chars? And what did you try already?
Naweed Niaz
Naweed Niaz 2020 年 10 月 21 日
its currently imported as a datetime vector, and I haven't tried anything because I am unsure of how to do this.

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2020 年 10 月 21 日
編集済み: Adam Danz 2020 年 10 月 23 日
Demo:
dt = datetime(1999,01,01) + days(1:100:5000);
y = rand(size(dt));
ax = gca();
plot(dt,y)
xtickformat(ax, 'yyyy')
% or
datetick(ax, 'x', 'yyyy', 'keeplimits')
  1 件のコメント
Peter Perkins
Peter Perkins 2020 年 11 月 19 日
Don't use datetick in a datetime plot. xtickformat is the way to go.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by