Plot date labels in x-axis
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
hmhuang
el 9 de Sept. de 2021
Respondida: Walter Roberson
el 9 de Sept. de 2021
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.
0 comentarios
Respuesta aceptada
Walter Roberson
el 9 de Sept. de 2021
xData = ["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]
x = datetime(xData, 'inputFormat', 'MM/dd', 'Format', 'MM/dd')
plot(x, yData)
0 comentarios
Más respuestas (1)
Chunru
el 9 de Sept. de 2021
xData = ["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]
% Convert the string to datetime
x = datetime(xData, 'InputFormat', 'MM/dd')
plot(x, yData)
datetick('x', 'mm/dd') % note the different case for month
0 comentarios
Ver también
Categorías
Más información sobre Discrete Data Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!