필터 지우기
필터 지우기

How to display XTicks from the command line?

조회 수: 1 (최근 30일)
Emerson De Souza
Emerson De Souza 2012년 10월 4일
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

채택된 답변

Walter Roberson
Walter Roberson 2012년 10월 4일
Plots do not have ticks, axes have ticks.
h = plot(xdate,count);
haxis = ancestor(h, 'axes');
set(haxis, 'XTick', xdate);
datetick(haxis, 'x', 'HHPM')
  댓글 수: 3
Walter Roberson
Walter Roberson 2012년 10월 4일
Is your count a 2D array instead of a vector? If so then you need to change to
haxis = ancestor(h(1), 'axes');
which will also work for the case where count is a vector.
Emerson De Souza
Emerson De Souza 2012년 10월 5일
Thank you Walter,
the line above fixes the problem.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by