How to display the Xticks from the command line?

1 次查看(过去 30 天)
INTRO: Hi I plot arbitrary data against date ticks for hours of the day as below:
%Get traffic count data
load count.dat
% Create arrays for an arbitrary date, here April 18, 1995
n = length(count);
year = 1990 * ones(1,n);
month = 4 * ones(1,n);
day = 18 * ones(1,n);
% Create arrays for each of 24 hours;
hour = 1:n;
minutes = zeros(1,n);
% Get the datenums for the data (only hours change)
xdate = datenum(year,month,day,hour,minutes,minutes);
% Plot the traffic data against datenums
plot(xdate,count)
% Update the graph's x-axis with date ticks
datetick('x','HHPM')
GOAL: I want to display the XTicks and modified the following lines:
h=subplot(1,1,1);
plot(xdate,count);
set(h,'XTick',xdate)
datetick(h,'x','HH','keepticks')
QUESTION: Why do I need to use subplot to display the XTick? I have also the version suggested by Walter:
h = plot(xdate,count);
haxis = ancestor(h, 'axes');
set(haxis, 'XTick', xdate);
datetick(haxis, 'x', 'HHPM')
but I still obtain the following error:
Error using set
Conversion to double from cell is not possible.
I wonder if someone could help me to correct these command lines and avoid the use of subplot.
Thank you in advance for your help
Emerson

采纳的回答

Babak
Babak 2012-10-4
x = -pi:.1:pi;
y = sin(x);
plot(x,y)
set(gca,'XTick',-pi:pi/2:pi)
set(gca,'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'})
title('Sine Function');
xlabel('Radians');
ylabel('Function Value');
  1 个评论
Emerson De Souza
Emerson De Souza 2012-10-5
Thank you Babak. But the problem is how to display Xtick combined with datetick (run the different codes above). The problem is, if I use datetick, then it seems that I have to use subplot to obtain the Xtick.
Do you know how to use the combination of both?
Thank you
Emerson

请先登录,再进行评论。

更多回答(0 个)

类别

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