views:

250

answers:

2

Any easy way to read all the columns in Matlab?

my format is

date time y1 y2 y3 y4 .........................
4/27/2010 00:3:09 34 45 45 56 ................

so on currently i am reading these with the code

[c,pathc]=uigetfile({'*.txt'},'Select the data','C:\Data');

file=[pathc c];
data= dlmread(file, ',', 1,3);

so needless to say i am skipping the time stamps.

Was wondering if there is aeasy way to read the time stamps and plot my other colums agianst the time in hours.

my files are 43200 X 30 and some are 86400 X 90

Related question : is the format same for .csv and .xls files , i mean except ofcourse xlsread

+1  A: 

I already answered to your question on the same data here: http://stackoverflow.com/questions/2588021/skip-reading-headers-in-matlab/2588353#2588353

[c,pathc]=uigetfile({'*.txt'},'Select the data','C:\Data');
file=[pathc c];
A = importdata(file, ' ', 1);
dt = datenum(A.textdata(2:end,1),'mm/dd/yyyy');
tm = datenum(A.textdata(2:end,2),'HH:MM:SS');
tm = dt+tm-datenum('0:0','HH:MM'); %# combine date and time and correct for zero time.
data = A.data;

You can plot your data against tm and use DATETICK function to show date in any format.

plot(tm,data)
datetick('x','HH')
xlabel('Time, hours')

EDIT

You can also use Jonas's solution for previous question to read the data. Then do same as above:

dt = datenum(dateAndTimeCell(:,1),'mm/dd/yyyy');
tm = datenum(dateAndTimeCell(:,2),'HH:MM:SS');
tm = dt+tm-datenum('0:0','HH:MM');

plot(tm,dataArray,'o-')
datetick('x','HH')
xlabel('Time, hours')
yuk
i get whole bunch of error and i do not understand them??? Error using ==> dlmread at 145Mismatch between file and format string.Trouble reading number from file (row 1,field 5) ==> :00:0Error in ==> dlmread at 90 result= dlmread(filename,delimiter,r,0);Error in ==> testwith_timestamps at 45data= dlmread(file, ',', 1); ??? Error using ==> importdata at 199Unable to load file.
Paul
Use TEXTSCAN or FREAD for more complexformats.Error in ==> testwith_timestamps at 49A = importdata(file, ' ', 1);Caused by: Error using ==> vertcat CAT arguments dimensions are not consistent.
Paul
I used the same code as yours after my uiget command minus the dlmread i used as ur code imports the data
Paul
You cannot use dlmread to read non-numeric data. Dates are actually strings in the file. And use space as a separator, not comma. With dlmread you have to skip not only one row, but 2 left columns.
yuk
I corrected the code above.
yuk
It still gives me datenum errors??? Error using ==> datenum at 174DATENUM failed.Error in ==> testwith_timestamps at 51dt =datenum(A.textdata(2:end,1),'mm/dd/yyyy');Caused by: Error using ==> dtstr2dtnummx Failed on converting date string to date number.
Paul
Are you sure all rows have the same format? Any missing data? Check the A variable after importdata.
yuk
Do you have repeated headers as you described in the previous question?
yuk
They have the same format and no missing data. also i doubt i can use this as i compare data from different dates and each files are like 50mbs long. This way it just crashes.I have checked and picked files which do not have repeated headers. Thats a another problem and i am not including that here
Paul
I edited the answer. Check if the other solution will help. Are you sure the dates format is always correct and correspond to datenum statements?
yuk
A: 

I believe sscanf will do the trick for you.

dbrien

related questions