From: Walter Roberson on 25 Jun 2010 18:47 "Steven " <stevenvandepavert(a)gmail.com> wrote in message > fid = fopen(strcat('C:\test\', 'FILENAME.txt' )); > Data = textscan(fid, '%d64 %*s %d32 %*f %*f %f %f %*f %*f %*f %*f'); > fclose(fid); > ------ > > When using a txt file containing the following data, the variable Data ends up as it should: > > 29375 SMP 1 170.19 109.94 79 76 158.63 630.3 538.69 1 > > How3ver, when using this file, Data ends up as an 1x4 empty array: > > 15555 SMP 1 183.64 93.76 68 70 179.83 435.65 418.87 1 Double check in case the leading 1 is a lower-case L. Also note that instead of all those %*f at the end, you can use %*[^\n] which will gobble everything to the end of the line.
From: Steven on 26 Jun 2010 06:00 Eureka: The first .txt file was coded in an ANSI format, while the second .txt file was coded in a unicode format. textscan can apparently only read the ANSI format. thank you all, Steven
From: per isakson on 26 Jun 2010 10:21 "Steven " <stevenvandepavert(a)gmail.com> wrote in message <i04j3r$9ie$1(a)fred.mathworks.com>... > Eureka: > > The first .txt file was coded in an ANSI format, while the second .txt file was coded in a unicode format. > > textscan can apparently only read the ANSI format. > > thank you all, > > Steven I read text-files with this code. A few years ago I found that FREAD handles most encodings. fid = fopen( ipv.FileSpec, 'r', 'n', ipv.Encoding ); buf = fread( fid, inf, '*char' ); sts = fclose( fid ); In a following step I read buf with STRREAD, but TEXTSCAN might be a better alternative. / per
First
|
Prev
|
Pages: 1 2 Prev: Install problem: error while loading shared libraries: libXp.so.6 Next: Fmincon |