필터 지우기
필터 지우기

Plot date labels in x-axis

조회 수: 16 (최근 30일)
hmhuang
hmhuang 2021년 9월 9일
답변: Walter Roberson 2021년 9월 9일
I have a plot with dates in form of mm/dd as x-axis data. Now I have
xData = ["01/22" "01/23" "01/24" "01/25" "01/26" "01/27" "01/28" "01/29"]
which is a string array of size 1 x 8.
How do I plot with
yData = [557 655 941 1433 2118 2927 5578 6167]
by using something like
plot(xData, yData)
with ["01/22" "01/23" "01/24" "01/25" "01/26" "01/27" "01/28" "01/29"] as the x-axis tick labels?
Currently I got the error messages "Error using plot.
Not enough input arguments." when running plot(xData, yData) as above, which I don't know what it exactly means.

채택된 답변

Walter Roberson
Walter Roberson 2021년 9월 9일
xData = ["01/22" "01/23" "01/24" "01/25" "01/26" "01/27" "01/28" "01/29"]
xData = 1×8 string array
"01/22" "01/23" "01/24" "01/25" "01/26" "01/27" "01/28" "01/29"
yData = [557 655 941 1433 2118 2927 5578 6167]
yData = 1×8
557 655 941 1433 2118 2927 5578 6167
x = datetime(xData, 'inputFormat', 'MM/dd', 'Format', 'MM/dd')
x = 1×8 datetime array
01/22 01/23 01/24 01/25 01/26 01/27 01/28 01/29
plot(x, yData)

추가 답변 (1개)

Chunru
Chunru 2021년 9월 9일
xData = ["01/22" "01/23" "01/24" "01/25" "01/26" "01/27" "01/28" "01/29"]
xData = 1×8 string array
"01/22" "01/23" "01/24" "01/25" "01/26" "01/27" "01/28" "01/29"
yData = [557 655 941 1433 2118 2927 5578 6167]
yData = 1×8
557 655 941 1433 2118 2927 5578 6167
% Convert the string to datetime
x = datetime(xData, 'InputFormat', 'MM/dd')
x = 1×8 datetime array
22-Jan-2021 23-Jan-2021 24-Jan-2021 25-Jan-2021 26-Jan-2021 27-Jan-2021 28-Jan-2021 29-Jan-2021
plot(x, yData)
datetick('x', 'mm/dd') % note the different case for month

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by