Control long datetime xtick

조회 수: 1 (최근 30일)
Day Hong Kim
Day Hong Kim 2021년 4월 17일
댓글: Day Hong Kim 2021년 4월 18일
Hello. I have an array that starts from 2015 to the end of 2020 every 10 minutes. This is my x-axis. When I plot this the x-axis only shows years, but I would like to show every years and months. I attached the m_file. If you guys know how to do this or tell me some tips for controlling the x-axis, I would be really thankful.

채택된 답변

Walter Roberson
Walter Roberson 2021년 4월 17일
편집: Walter Roberson 2021년 4월 17일
basedate = datetime(2015,1,1,0,0,0, 'Format', 'yy/MM');
enddate = datetime(2020,12,31,23,59,59, 'Format', 'yy/MM');
wanted_ticks = basedate + calmonths(0:(2020-2015+1)*12)
wanted_ticks = 1×73 datetime array
15/01 15/02 15/03 15/04 15/05 15/06 15/07 15/08 15/09 15/10 15/11 15/12 16/01 16/02 16/03 16/04 16/05 16/06 16/07 16/08 16/09 16/10 16/11 16/12 17/01 17/02 17/03 17/04 17/05 17/06 17/07 17/08 17/09 17/10 17/11 17/12 18/01 18/02 18/03 18/04 18/05 18/06 18/07 18/08 18/09 18/10 18/11 18/12 19/01 19/02 19/03 19/04 19/05 19/06 19/07 19/08 19/09 19/10 19/11 19/12 20/01 20/02 20/03 20/04 20/05 20/06 20/07 20/08 20/09 20/10 20/11 20/12 21/01
sample_dates = linspace(basedate, enddate, 30);
plot(sample_dates, rand(size(sample_dates)))
xticks(wanted_ticks)
  댓글 수: 1
Day Hong Kim
Day Hong Kim 2021년 4월 18일
Thank you for the code. I will study the code and apply into my script. Have a great day!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by