How to extract tick label in sequence data

2 Ansichten (letzte 30 Tage)
suling yin
suling yin am 13 Jan. 2021
Kommentiert: Cris LaPierre am 13 Jan. 2021
I have irregular sequence data as:
2019/1/1 3:00:00, 1
2019/1/1 4:00:00, 2
2019/1/2 3:00:00, 3
2019/1/2 5:00:00, 4
2019/1/2 6:00:00, 5
2019/1/2 7:00:00, 6
2019/1/3 2:00:00, 7
2019/1/3 3:00:00, 8
2019/1/3 4:00:00, 9
2019/1/4 3:00:00, 10
2019/1/4 4:00:00, 11
2019/1/5 1:00:00, 12
2019/1/5 3:00:00, 13
and I want to extract the following tick labels and their position when I plot the data
position label
1 1/1
3 1/2
7 1/3
10 1/4
12 1/5

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 13 Jan. 2021
What do you mean you want to extract them? Do you mean set them?
Look at the xticks and xticklabels functions.
x = linspace(0,10);
y = x.^2;
plot(x,y)
xticks([0 5 10])
xticklabels(["x = 0","x = 5","x = 10"])
  2 Kommentare
suling yin
suling yin am 13 Jan. 2021
thanks for your reply
yes, I mean I want to set them
but the following are the my expected result
position label
1 1/1
3 1/2
7 1/3
10 1/4
12 1/5
In fact, I just want to find the first position of each day in my example data.
Cris LaPierre
Cris LaPierre am 13 Jan. 2021
In fact, I just want to find the first position of each day in my example data.
This would be good information to include in the orginal question.
data = readtable("datesVals.csv","Format",'%{yyyy/MM/dd HH:mm:ss}D %f')
data = 13x2 table
Var1 Var2 ___________________ ____ 2019/01/01 03:00:00 1 2019/01/01 04:00:00 2 2019/01/02 03:00:00 3 2019/01/02 05:00:00 4 2019/01/02 06:00:00 5 2019/01/02 07:00:00 6 2019/01/03 02:00:00 7 2019/01/03 03:00:00 8 2019/01/03 04:00:00 9 2019/01/04 03:00:00 10 2019/01/04 04:00:00 11 2019/01/05 01:00:00 12 2019/01/05 03:00:00 13
tDays = groupsummary(data,"Var1","day",'min',"Var1")
tDays = 5x3 table
day_Var1 GroupCount min_Var1 ___________ __________ ___________________ 01-Jan-2019 2 2019/01/01 03:00:00 02-Jan-2019 4 2019/01/02 03:00:00 03-Jan-2019 3 2019/01/03 02:00:00 04-Jan-2019 2 2019/01/04 03:00:00 05-Jan-2019 2 2019/01/05 01:00:00
plot(data.Var1,data.Var2)
xticks(tDays.min_Var1);
xticklabels("1/" + num2str(day(tDays.min_Var1)))

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by