A little exercise with regular expression
>> cssm( 'BFND_W6.txt' )
ans =
struct with fields:
FP1: 'Invalid'
FP2: 'Invalid'
FP3: 'Right'
FP4: 'Left'
where
function sas = cssm( ffs )
%%
xpr = ['^FP1\x20*=\x20*(?<FP1>\S+).*' ...
,'^FP2\x20*=\x20*(?<FP2>\S+).*' ...
,'^FP3\x20*=\x20*(?<FP3>\S+).*' ...
,'^FP4\x20*=\x20*(?<FP4>\S+)' ];
sas = regexp( chr, xpr, 'names', 'lineanchors');
end
Comments:
- the "rows" of xpr must appear in the same order as the rows in the data file, i.e. FP1,FP2,FP3,FP4
- \x20 is a way to indicate space without using space (it's hex).
- Space around = isn't needed for this sample file, but just in case.
- The first FPn in a "row" is the name in the text file, the next FPn is the name of the resulting structure field.