سؤال

I am trying to interpret data from an eye tracking device. The files exported from the eye tracker are in ASCII format.

Recording files that contain data from a single eye only look like this (only four rows shown):

6372825   645.3   275.4  1362.0 ...
6372826   644.6   274.0  1364.0 ...
6372827   644.2   273.2  1365.0 ...
6372828   642.5   272.7  1367.0 ...

Note that the dots at the end of each row above are a part of the output file, i.e. I haven't added them for the purposes of this question. I normally detect these dots and later throw them away.

The format of the above columns is [timestamp, X, Y, pupilSize, {...}]

A recording from both eyes looks like this (only four rows shown):

505076    416.8   755.4  1148.0    23.6   751.1  1239.0 .....
505077    417.0   758.4  1143.0    23.7   753.1  1244.0 .....
505078    416.7   761.4  1146.0    24.6   752.1  1249.0 .....
505079    416.1   764.8  1150.0    27.3   750.2  1250.0 .....

In this case, the data format is [timestamp, X(left), Y(left), pupilSize(left), X(right), Y(right), pupilSize(right), {.....}]

In both cases, I'd like to extract the numbers from the text and assign them to an array. Here's how I do this for recordings from a single eye:

eyeData = textscan(fid,'%d %f %f %f %s');

I can do the same for binocular recordings, using the following code:

eyeData = textscan(fid,'%d %f %f %f %f %f %f %s');

The trouble is, I'd like to be able to automatically detect whether the data I'm dealing with are monocular or binocular. In other words, I need a way of determining whether the ASCII file has five columns or eight. Note that the last column in both cases just consists of a series of dots. Whilst I typically just throw this away, it may be useful in determining the number of eyes in the recording (since monocular recordings end each row with ... and binocular with .....)

Any ideas as to how I might work out how many columns are in each ASCII file are welcome!

هل كانت مفيدة؟

المحلول

You can read the first data line, check the number of columns and then revert the file position indicator For example:

pos = ftell(fid);
cols = numel(regexp(fgetl(fid), '\s*([^\s]*)\s*'));
fseek(fid, pos, 'bof');

This can be followed by:

if (cols == 5)
    eyeData = textscan(fid, '%d %f %f %f %s');
else
    eyeData = textscan(fid, '%d %f %f %f %f %f %f %s');
end

By the way, note that you can tell textscan to discard the dots by using %*s instead of the last %s in the pattern string.

نصائح أخرى

You can count the columns in a file with a shell command, which you can call from MATLAB using

s = system(shell_command);

To produce a 'shell_command' that fits your needs check out the following link

unix - count of columns in file

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top