How to plot some xtickslabel that correspond to y data?

2 ビュー (過去 30 日間)
Arthur
Arthur 2012 年 12 月 12 日
Hello!
I've read a lot of answers about xticklabel and datetick, but i'm very confusing yet.
I have two vectors of 30 points.
y = 30 points
x = 30 points type date string (i've used datestr() from a datenum() number) (HH:MM:SS.FFF). See like this:
' 06:22:19.041'
' 06:22:19.048'
' 06:22:19.050'
' 06:22:19.055' ...
I used the plot function only for the y data:
plot(y);
The x data on the graphic was = 1...5...10...15...20...25...30. (7 numbers!)
So, i changed the xtickslabels:
set(gca, 'XTickLabel', x);
And the xtickslabels changed for the only the first 7 numbers of my x vector.
I need plot few points, as i did, but the points on xticks have to correspond to the y data.
Thanks. Sorry about the language

回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 12 月 12 日
set(gca, 'XTick', 1:length(x), 'XTickLabel', x);
  10 件のコメント
Arthur
Arthur 2012 年 12 月 13 日
I did some tests here. I realy thank your help.
In some plots, the seconds, miliseconds and the minutes are changing. i want to plot the x axis in MM:SS.FFF format. So guess only the strings will do it to me.
Can you plot on x axis a string vector 'dateticks' and erase some data to improve the visualization? Replacing some data to a blank ' '?
This graphics will be a part of an research article and the reviser suggested that i should do in this way... :s. I'm sending here the two complete vectors to plot.
K>> v_fase_a_evento_agreg{1,1}
ans =
99.1
99.1
99.2
99.1
99
99.1
99.1
99.1
99.1
99.2
99.1
99.1
99
98.4
98.5
98.4
98.2
99.1
99.4
98.6
98.5
99
99.1
98.6
98.4
98.9
99.1
98.8
98.5
99
K>> t_event_agreg{1,1}
ans =
' 06:22:19.041'
' 06:22:19.046'
' 06:22:19.050'
' 06:22:19.054'
' 06:22:19.058'
' 06:22:19.062'
' 06:22:19.066'
' 06:22:19.071'
' 06:22:19.075'
' 06:22:19.079'
' 06:22:19.083'
' 06:22:19.087'
' 06:22:19.088'
' 06:22:19.096'
' 06:22:19.097'
' 06:22:19.104'
' 06:22:19.108'
' 06:22:19.112'
' 06:22:19.116'
' 06:22:19.121'
' 06:22:19.125'
' 06:22:19.129'
' 06:22:19.133'
' 06:22:19.137'
' 06:22:19.141'
' 06:22:19.145'
' 06:22:19.150'
' 06:22:19.154'
' 06:22:19.158'
' 06:22:19.162'
Arthur
Arthur 2012 年 12 月 13 日
Walter,
I found a solution for now, but a manual solution. plot(y); f=datestr(t_event_agreg{1,1},'HH:MM:SS.FFF'); set(gca,'XTick',1:length(f),'XTickLabel', f);
So i went to figure properties /Ticks and erase some LABELS keeping the locations. It is my solution for only one graphic.
after, I used this command to check:
get(gca,'Xticklabel') ans =
'06:22:19.041'
''
''
''
'06:22:19.058'
''
''
''
''
'06:22:19.079'
''
''
''
''
'06:22:19.097'
''
''
''
''
'06:22:19.121'
''
''
''
''
'06:22:19.141'
''
''
''
''
'06:22:19.162'
How can i modify the orginal vector of time e fill it with 'blanks'???

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGrid 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