about convert time data and plotting

Hi. I have a question about converting time data
I have time data in double and Thickness data of water mass I calculated.
Attached TDD(TDD(:,1)=Thick, TDD(:,2)=time data )
So I draw plot using them.
I want to convert xlabelstick to months.ex) 01 02 03 04 --- 11 12
Thank you for your help.

 採用された回答

Chunru
Chunru 2022 年 7 月 22 日
編集済み: Chunru 2022 年 7 月 22 日

0 投票

load("TDD.mat")
%TDD
subplot(121);
plot(datetime(TDD(:,2),'ConvertFrom','datenum'), TDD(:,1), '.');
datetick('x', "mm/dd"); % doc datetick for more options
subplot(122);
plot(datetime(TDD(:,2),'ConvertFrom','datenum', 'Format', 'MM/dd'), TDD(:,1), '.');
%datetick('x', "MM/dd"); % doc datetick for more options

7 件のコメント

주희 박
주희 박 2022 年 7 月 22 日
Thanks, but i got an error .
Did you multiply 1.0e+05 *?
Walter Roberson
Walter Roberson 2022 年 7 月 22 日
You should not use datetick() together with datetime() objects. Instead you should use 'Format' when you construct the datetime() object.
Chunru
Chunru 2022 年 7 月 22 日
@Walter Roberson Updated. See the difference.
Chunru
Chunru 2022 年 7 月 22 日
@주희 박 No multiplication by 1.0e+05.
Walter Roberson
Walter Roberson 2022 年 7 月 22 日
The odd 04/01 has to do with the automatic range selection rounding to "nice" numbers, together with the fact that you asked for month and day number (not for month and year). So the 01/01 is month january (1) day 1 of 2000, and the 04/1 is month april (4) day 1 of 2000.
Chunru
Chunru 2022 年 7 月 22 日
I would like to point out that with "datetick('x', "mm/dd")" we can explicitly choose the data format as month/day. With datetime(TDD(:,2),'ConvertFrom','datenum', 'Format', 'MM/dd'), the format is changed to "Jan" and so on. It seems that datetick('x', "mm/dd") should be the command to change the tick setting. The datetime format command seems failed to do so.
주희 박
주희 박 2022 年 7 月 23 日
you both so genious. And I can get right answer when I use Matlab2022. (I used 2021 yesterday). Thank you so much. Thanks.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 7 月 22 日

0 投票

load TDD
thick = TDD(:,1);
dt = datetime(TDD(:,2),'ConvertFrom', 'datenum', 'Format', 'MM');
scatter(dt, thick, '.')

1 件のコメント

주희 박
주희 박 2022 年 7 月 23 日
Thank you . It is so helpful to me.

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

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

質問済み:

2022 年 7 月 22 日

コメント済み:

2022 年 7 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by