MATLAB: Searching multiple Strings in file

find stringsregexpstrfind

Hi,
The typical file format is as follows:
channelCfg 15 3 0
adcCfg 2 1
adcbufCfg -1 0 0 1 0
The text file is read. The keywords are adcCfg and adcbufCfg. Searching for the keywords only integers in that line have to be stored in a vector. I tried to get something to work with regexp and strfind but got no satisfying results.
Regards

Best Answer

but got no satisfying results
And what is a statisfying result?
Is this what you're after?
filecontent = fileread('c:\somewhere\somefile.txt');
adclines = regexp(filecontent, '(?<=adc(buf)?Cfg).*', 'match', 'dotexceptnewline');
adcnumbers = cellfun(@str2double, regexp(adclines, '[+-]?\d+', 'match'), 'UniformOutput', false);
celldisp(adcnumbers)