The problem is that space is used as delimiter between the second and third column. Your format string, '%s %s %d8 %f %f %s', indicates six columns. However, the header says five columns.
See the documentation on textscan.
Try
>> cac = cssm()
cac =
{7x1 cell} {7x1 cell} [7x1 double] [7x1 double] [7x1 double] {7x1 cell}
>> cac{2}
ans =
'S'
'S'
'S'
'S'
'S'
'S'
'S'
>>
where
function cac = cssm()
fid = fopen('cssm.txt');
cac = textscan( fid, '%s%s%f%f%f%s', 'Delimiter', ', ' ...
, 'Headerlines', 2, 'MultipleDelimsAsOne', true );
fclose(fid);
end
and where cssm.txt contains
Sampling rate: 1024Hz, SamplingInterval: 0.9765625ms
Type, Description, Position, Length, Channel
Stimulus, S 3, 5333, 1, All
Stimulus, S 1, 9441, 1, All
Stimulus, S 3, 12526, 1, All
Stimulus, S 2, 15610, 1, All
Stimulus, S 3, 24140, 1, All
Stimulus, S 2, 27934, 1, All
Stimulus, S 3, 31019, 1, All
.
Or five columns
>> cac = cssm()
cac =
{7x1 cell} {7x1 cell} [7x1 double] [7x1 double] {7x1 cell}
>> cac{2}
ans =
'S 3'
'S 1'
'S 3'
'S 2'
'S 3'
'S 2'
'S 3'
>>
where
function cac = cssm()
fid = fopen('cssm.txt');
cac = textscan( fid, '%s%s%f%f%s', 'Delimiter', ',', 'Headerlines', 2 );
fclose(fid);
end
Best Answer