MATLAB: Extracting a number from an input (text file)

data extract

in the middle of my program, I need to read a Number from a file (text or DAT). This is a part of the file
##$SUBNAM9= <"">
##$SW= 2776.7173944802
##$SWIBOX= (0..15)
0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0
##$SW_h= 833333.333333333
##$SWfinal= 0
##$TD= 16384
##$TD0= 1
##$TE= 300
##$TE2= 300
I want Matlab to first read this file, then search for the number in front of "##$TD= ", which is 16384 in this example. Then
TD = 16384;
Thanks in advance

Best Answer

T = regexp(TheString, '^##\$TD=\s*(.*) \s*$', 'tokens');
Then T{1} will be the string of the number. str2double(T{1}) if you want the numeric value.