开发者

Date and time in Matlab on x axe

I have a txt file as

20100318,1630,17.3600,1开发者_如何学编程7.3700,17.2900,17.3000,150408
20100318,1700,17.3000,17.3200,17.2700,17.3200,69629
20100318,1730,17.3100,17.3100,17.3100,17.3200,0
20100319,900,17.4000,17.5600,17.3500,17.5100,460691
20100319,930,17.5100,17.5400,17.4200,17.4200,143917

where first and second columns are Date and Time with commas as columns separator.

I would like to have Date and Time on x axe without empty spaces between 1730 (last record of each days) and 900 (first record of next day).


Here's one way to do this (assuming the txt-file is called 'test.txt'):

data = csvread('test.txt');              %# read the txt file
plot(data(:,6));                         %# plot the data
date = num2str(data(:,1));               %# read date
time = num2str(data(:,2));               %# read time
dt = [date,repmat(' ',size(data,1),1),time]; %# combine date and time
set(gca,'xtick',1:size(data,1),'xticklabel',dt) %# set axes labels

Note that there are fancier ways to create the date-time strings, and that you may be interested in using ROTATETICKLABELS from the file exchange for better visibility of date and time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜