f



problem with importing text with number and text

i am trying to import a csv file (~49000 rows x 52 cols) with numbers text and characters in it and not getting through. xlsread works fine with all my data except the first column of data which is a time stamp. it converts the time stamps into a constant value through the entire column. To add to the problem, when opened as a text file, every row of the file starts with a comma. I got very close with textscan/textread with all the data coming in but all the rows are transposed into one column one above the other ( imagine 49000 rows 52 cells long transposed one above the other in one column creates a 2 million x 1 cell array). The only data i want to bring in is the first column as the rest of the data comes in fine with xlsread. any help would be greatly appreciated.

this is how a section of the data looks 
Log File Version ,2.3
8/31/2010 11:09:33 AM
--------------------------
Parameter Name,PC Timestamp, xxxx, x , x ,x ,x --------. continues 52 cols 
Units,none,none,bar,bar,g/sec, x ,x ,x ,x ,x ,x ,x 
Source Address,,,0x00,0x00,0x00,0x00,0x00,0x00
,11:09:33.782,0,600.3,607.20,3.26,14.14,0.14,4  ---> row where data starts 
,11:09:33.798,0,600.0,602.56,3.39,14.11, 15,14
|
|
|
|
V
49000 rows 
0
abishek
1/18/2011 6:52:05 PM
comp.soft-sys.matlab 211266 articles. 22 followers. lunamoonmoon (257) is leader. Post Follow

3 Replies
1171 Views

Similar Articles

[PageSpeed] 21

On 11-01-18 12:52 PM, abishek muralidharan wrote:
> i am trying to import a csv file (~49000 rows x 52 cols) with numbers text and
> characters in it and not getting through. xlsread works fine with all my data
> except the first column of data which is a time stamp. it converts the time
> stamps into a constant value through the entire column. To add to the problem,
> when opened as a text file, every row of the file starts with a comma. I got
> very close with textscan/textread with all the data coming in but all the rows
> are transposed into one column one above the other ( imagine 49000 rows 52
> cells long transposed one above the other in one column creates a 2 million x
> 1 cell array). The only data i want to bring in is the first column as the
> rest of the data comes in fine with xlsread. any help would be greatly
> appreciated.
>
> this is how a section of the data looks Log File Version ,2.3
> 8/31/2010 11:09:33 AM
> --------------------------
> Parameter Name,PC Timestamp, xxxx, x , x ,x ,x --------. continues 52 cols
> Units,none,none,bar,bar,g/sec, x ,x ,x ,x ,x ,x ,x Source
> Address,,,0x00,0x00,0x00,0x00,0x00,0x00
> ,11:09:33.782,0,600.3,607.20,3.26,14.14,0.14,4 ---> row where data starts
> ,11:09:33.798,0,600.0,602.56,3.39,14.11, 15,14
> |
> |
> |
> |
> V
> 49000 rows

t = textscan(fid, '%*c%[^,]%*[^\n]', 'Delimiter', '\n');
timestamps = t{1};
%datenum() the timestamps if you want them in numeric form.

Though I'd probably just read it all with textscan() rather than mixing 
xlsread and textscan
0
Think
1/18/2011 7:07:11 PM
"Think two, count blue." <roberson@hushmail.com> wrote in message <ih4og0$mqn$1@nrc-news.nrc.ca>...
> On 11-01-18 12:52 PM, abishek muralidharan wrote:
> > i am trying to import a csv file (~49000 rows x 52 cols) with numbers text and
> > characters in it and not getting through. xlsread works fine with all my data
> > except the first column of data which is a time stamp. it converts the time
> > stamps into a constant value through the entire column. To add to the problem,
> > when opened as a text file, every row of the file starts with a comma. I got
> > very close with textscan/textread with all the data coming in but all the rows
> > are transposed into one column one above the other ( imagine 49000 rows 52
> > cells long transposed one above the other in one column creates a 2 million x
> > 1 cell array). The only data i want to bring in is the first column as the
> > rest of the data comes in fine with xlsread. any help would be greatly
> > appreciated.
> >
> > this is how a section of the data looks Log File Version ,2.3
> > 8/31/2010 11:09:33 AM
> > --------------------------
> > Parameter Name,PC Timestamp, xxxx, x , x ,x ,x --------. continues 52 cols
> > Units,none,none,bar,bar,g/sec, x ,x ,x ,x ,x ,x ,x Source
> > Address,,,0x00,0x00,0x00,0x00,0x00,0x00
> > ,11:09:33.782,0,600.3,607.20,3.26,14.14,0.14,4 ---> row where data starts
> > ,11:09:33.798,0,600.0,602.56,3.39,14.11, 15,14
> > |
> > |
> > |
> > |
> > V
> > 49000 rows
> 
> t = textscan(fid, '%*c%[^,]%*[^\n]', 'Delimiter', '\n');
> timestamps = t{1};
> %datenum() the timestamps if you want them in numeric form.
> 
> Though I'd probably just read it all with textscan() rather than mixing 
> xlsread and textscan



works like a charm...thanks a bunch
0
abishek
1/18/2011 7:54:05 PM
"abishek muralidharan" <mabishek@gmail.com> wrote in message <ih4r4t$fcq$1@fred.mathworks.com>...
> "Think two, count blue." <roberson@hushmail.com> wrote in message <ih4og0$mqn$1@nrc-news.nrc.ca>...
> > On 11-01-18 12:52 PM, abishek muralidharan wrote:
> > > i am trying to import a csv file (~49000 rows x 52 cols) with numbers text and
> > > characters in it and not getting through. xlsread works fine with all my data
> > > except the first column of data which is a time stamp. it converts the time
> > > stamps into a constant value through the entire column. To add to the problem,
> > > when opened as a text file, every row of the file starts with a comma. I got
> > > very close with textscan/textread with all the data coming in but all the rows
> > > are transposed into one column one above the other ( imagine 49000 rows 52
> > > cells long transposed one above the other in one column creates a 2 million x
> > > 1 cell array). The only data i want to bring in is the first column as the
> > > rest of the data comes in fine with xlsread. any help would be greatly
> > > appreciated.
> > >
> > > this is how a section of the data looks Log File Version ,2.3
> > > 8/31/2010 11:09:33 AM
> > > --------------------------
> > > Parameter Name,PC Timestamp, xxxx, x , x ,x ,x --------. continues 52 cols
> > > Units,none,none,bar,bar,g/sec, x ,x ,x ,x ,x ,x ,x Source
> > > Address,,,0x00,0x00,0x00,0x00,0x00,0x00
> > > ,11:09:33.782,0,600.3,607.20,3.26,14.14,0.14,4 ---> row where data starts
> > > ,11:09:33.798,0,600.0,602.56,3.39,14.11, 15,14
> > > |
> > > |
> > > |
> > > |
> > > V
> > > 49000 rows
> > 
> > t = textscan(fid, '%*c%[^,]%*[^\n]', 'Delimiter', '\n');
> > timestamps = t{1};
> > %datenum() the timestamps if you want them in numeric form.
> > 
> > Though I'd probably just read it all with textscan() rather than mixing 
> > xlsread and textscan
> 
> 
> 
> works like a charm...thanks a bunch


i recently found that the textscan function solution in post #2 works only when there are 2 characters before the first colon in the timestamp. for eg. it would work if the timestamp is 11:09:35 but not if its 7:09:35 since its defined to look at 2 digits. How do i make the syntax independent of the number of digits and just base it off of the ":" that sepearates the hours mins and seconds ?
0
mabishek (3)
3/3/2011 6:02:08 PM
Reply: