textscan doesn't scan data, but does scan similar data

textscan doesn't scan data, but does scan similar data

Post by Steve » Sun, 27 Jun 2010 02:32:06


i all,

I am stuck on a problem in one of my scripts.
In this script I am using the textscan function to read a .txt file into an array.

The code I am using is:

fid = fopen(strcat(OPENPATH, FILENAME));
Data = textscan(fid, '%d64 %*s %d32 %*f %*f %f %f %*f %*f %*f %*f', 'headerLines', 23, ...
'treatAsEmpty', {'MSG', TRIALSEPARATOR}, 'emptyValue', 0);
fclose(fid);

If I read the following .txt data into this array, everything works fine:
------------------------------------------------------------------------------
## [iView]
## Converted from: C:\Program Files\SMI\iView X\data\Steven\LaVie\TestingData\EyeTracker\107FR26ES1.idf
## Date: 28.01.2010 09:17
## Version: IDF Converter 2.01 build 21
## Sample Rate: 240
## [Trial]
## User:
## Trial:
## [Calibration]
## Calibration Type: 9-point with corner correction
## Calibration Area: 1280 1024
## [Geometry]
## Stimulus Dimension [mm]: 300 200
## Head Distance [mm]: 900
## [Hardware Setup]
## [Presentation]
## Number of Samples: -100
## Reversed: none
## Format: LEFT. RAW. DIAMETER. CR. POR
##
Time Type Set L Raw X [px] L Raw Y [px] L Dia X [px] L Dia Y [px] L CR1 X [px] L CR1 Y [px] L POR X [px] L POR Y [px]
17265383271 MSG Scene Image: C:\Program Files\SMI\iView X\CAL1280.BMP
0 SMP 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
29375 SMP 1 170.19 109.94 79 76 158.63 630.3 538.69 1
29376 SMP 1 170.18 109.92 79 74 158.64 630.25 538.39 1
29377 SMP 1 170.11 109.99 79 74 158.52 630.64 538.35 1
29378 SMP 1 169.26 110.11 79 76 158.05 622.87 541.67 1
29379 SMP 1 167.53 110.05 80 76 157.39 581.02 541.22 1
29380 SMP 1 165.63 109.68 79 74 156.71 537.78 522.85 1
29381 SMP 1 164.47 109.44 79 74 156.26 513.32 506.54 1
29382 SMP 1 164.16 109.55 79 74 155.99 512.54 508.55 1
29383 SMP 1 164.52 109.74 79 74 155.96 523.12 513.78 1
29384 SMP 1 164.77 109.87 79 74 156.05 528.25 516.28 1
29385 SMP 1 165.07 110.02 80 74 156.22 532.83 522.32 1
29386 SMP 1 165.24 110 80 74 156.32 535.55 521.63 1
etcetera.
--------------------------

However, when trying to read the following .txt file. Data ends up being an empty 1x4 array:
------------------
## [iView]
## Converted from: C:\Program Files\SMI\iView X\data\Steven\LaVie\TestingData\EyeTracker\114FL23ES2part1.idf
## Date: 27.01.2010 13:38
## Version: IDF Converter 2.01 build 21
## Sample Rate: 240
## [Trial]
## User:
## Trial:
## [Calibration]
## Calibration Type: 9-point with corner correction
## Calibration Area: 1280 1024
## [Geometry]
## Stimulus Dimension [mm]: 300 200
## Head Distance [mm]: 900
## [Hardware Setup]
## [Presentation]
## Number of Samples: -100
## Reversed: none
## Format: LEFT. RAW. DIAMETER. CR. POR
##
Time Type Set L Raw X [px] L Raw Y [px] L Dia X [px] L Dia Y [px] L CR1 X [px] L CR1 Y [px] L POR X [px] L POR Y [px]
4485531414 MSG Scene Image: C:\Program Files\SMI\iView X\CAL1280.BMP
0 SMP 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
32421 SMP 1 183.64 93.76 68 70 179.83 435.65 418.87 1
32422 SMP 1 182.98 93.76 69 70 179.72 414.05 418.02 1
32423 SMP 1 182.83 93.63 69 70 179.55 412.66
 
 
 

textscan doesn't scan data, but does scan similar data

Post by Steve » Sun, 27 Jun 2010 02:39:05

pdate after seeing how the message displays data:

note that the data as shown in the message is not exactly in the same format as the actual .txt files.

In both cases the 23rd line is:
0 SMP 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00


Steven


"Steven " < XXXX@XXXXX.COM > wrote in message <i02p6m$rlh$ XXXX@XXXXX.COM >...

 
 
 

textscan doesn't scan data, but does scan similar data

Post by us » Sun, 27 Jun 2010 02:40:27

Steven " < XXXX@XXXXX.COM > wrote in message <i02p6m$rlh$ XXXX@XXXXX.COM >...

ok... nice copy/paste...
but for those CSSMers, who don't have a lot of time:
can you just show the difference - please...

us
 
 
 

textscan doesn't scan data, but does scan similar data

Post by Steve » Sun, 27 Jun 2010 02:53:04


That's exactly the point, I don't know what the difference is.
 
 
 

textscan doesn't scan data, but does scan similar data

Post by Steve » Sun, 27 Jun 2010 06:06:05

Hi,

I simplified the question I am having, so someone hopefully can provide a solution.

The issue I am having with my textscan function is the following:

I am using this code:
------
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

Hence my question, why? And how do I solve this?

thanks a lot in advance,
Steven
 
 
 

textscan doesn't scan data, but does scan similar data

Post by Walter Rob » Sun, 27 Jun 2010 07:47:22


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.
 
 
 

textscan doesn't scan data, but does scan similar data

Post by Steve » Sun, 27 Jun 2010 19:00:28

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
 
 
 

textscan doesn't scan data, but does scan similar data

Post by per isakso » Sun, 27 Jun 2010 23:21:04


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