views:

45

answers:

1

I have a txt file as

20100318,1630,17.3600,17.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).

+1  A: 

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.

Jonas
Thanks for your reply: it works but it plots only in 1030 - 1530 time range while Time range from 900 up to 1730 each day.If I scroll left right with hand tool first and last time plot are always 1030 and 1530
Alberto acepsut
@Alberto acepsut: When I plot the data in your post, I get five data points, the first being 1630, the last being 930, because these are the first and the last time in the file, respectively. Did you check the first and the last line in your data file?
Jonas
Well I just wrote some sample rows since I can't post here more than 600 characters.Time frame is 30 minutes starting from 900 up to 1730 (530PM),18 rows each day.My complete data file starts with 20100318,1030,17.3000,17.3300,17.2900,17.3000,106042as first row and end with20100428,1730,15.9300,15.9300,15.9300,16.0400,0as last rowI can post a whole day splitted in two replies
Alberto acepsut
20100319,900,17.4000,17.5600,17.3500,17.5100,46069120100319,930,17.5100,17.5400,17.4200,17.4200,14391720100319,1000,17.4400,17.5100,17.4000,17.5100,11543520100319,1030,17.5000,17.5500,17.4900,17.5100,20101120100319,1100,17.5000,17.5300,17.4700,17.5200,9341720100319,1130,17.5200,17.5700,17.5000,17.5000,20922520100319,1200,17.5000,17.5300,17.5000,17.5100,2774220100319,1230,17.5100,17.5500,17.5000,17.5400,5124620100319,1300,17.5400,17.5600,17.5200,17.5300,49402
Alberto acepsut
20100319,1330,17.5400,17.5400,17.5200,17.5300,3465620100319,1400,17.5300,17.5600,17.5200,17.5300,4046520100319,1430,17.5300,17.5600,17.5300,17.5300,7488220100319,1500,17.5300,17.5300,17.4500,17.4800,17451220100319,1530,17.4700,17.5600,17.4700,17.5400,25291420100319,1600,17.5400,17.5500,17.4600,17.4700,17295620100319,1630,17.4700,17.4700,17.4400,17.4400,8304920100319,1700,17.4400,17.5000,17.4300,17.5000,9577920100319,1730,17.4600,17.4600,17.4600,17.5000,0
Alberto acepsut
@Alberto acepsut: Since the first row of your file starts with 1030 in the time column, your plot will start at 1030. I am a bit surprised that the plot should stop at 1530, though, since the time in the last line is 1730. If you copy the single-day data you just posted into a new file, and run my code, will it plot from 900 to 1730?
Jonas
Just tried with the full day from 900 up to 1730 but I get the same result: now it plots from 900 up to 1200 and if I scroll left or right there is always 1200 as last right plot on x axys. While scrolling left it slides all time plots and displays only the 900 to 1200 time range.
Alberto acepsut
@Alberto acepsut: found the problem. You also have to set the location of the ticks. See the edited version of my answer.
Jonas
Thank you very much Jonas, now it works perfectly!
Alberto acepsut
@Alberto acepsut: If you found the answer useful, please consider accepting it.
Jonas
Yes your answer is useful, just turned to accepted.
Alberto acepsut