How to plot datetime in garfh?

조회 수: 1 (최근 30일)
Gili Kurtser
Gili Kurtser 2019년 10월 19일
답변: Peter Perkins 2019년 10월 30일
hello,
I have a grafh that looks like this.
Insted of the numbers in the X-axis I have a list of dates in the format ot datetime (DD/MM/YYYY)
this list is taken from a table.
I want to name the X-axis by the Dates (for exapmle 1=(datelist(1)) and so on...
how can I do this?
I am Using the contourf function to plot.
Thank you
  댓글 수: 1
darova
darova 2019년 10월 19일
Did you tried this?
set(gca,'YTickLabel',[1 2 3])

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

답변 (2개)

Payas Bahade
Payas Bahade 2019년 10월 22일
Hi Gili,
Function xticklabels’ can be used to change the x-axis labels. For that labels needs to be specified as a string array eg. {‘dd/mm/yyyy’,‘dd/mm/yyyy’}. If your list of dates is not in string array format, you can use function ‘char’ to convert your list into string array.
Following sample code illustrates use of ‘xticklabels’:
A={'22/01/2019','23/01/2019','24/01/2019','25/01/2019','26/01/2019'};% string array of dates
x=[1 2 3 4 5];% x-axis data
y=[4 7 11 8 16];% y-axis data
plot(x,y); % plotting x&y
xticks([1 2 3 4 5]); % specifying x-axis data whose labels needs to be displayed
xticklabels(A);% changing x-axis labels to dates stored in variable ‘A’
For more details please refer to the following documentation of ‘xticklabels’: https://www.mathworks.com/help/matlab/ref/xticklabels.html?s_tid=doc_ta#bvaeark-1
HTH!

Peter Perkins
Peter Perkins 2019년 10월 30일
Gili, you say datetime and table, so I'm going to assume you are using those datatypes. contour does not currently support datetimes, but it should be straight-forward to use an integer vector to define that axis of the mesh, and then use something like Payas' suggestion, using
timestamps = string(myTable.MyTimes)
as the text tick labels.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by