MATLAB: Read single “cell” containing partly text and numbers

delimiter readdlmreadMATLABsingle celltextstring

Hallo Matlab forum.
I have a problem with reading a single cell in a space separated text file. The cell is containing a letter and therefore dlmread isn't working.
Example of the file reading.
Kanal 1
Range 32768 N/Min/Max/Mean/Zero 3225000 88 288 184 0
Pressure sensor 1 (1)
X-POS/Y-POS/CAL/DIM 0 0 4.9681*x + -0.30715
Kanal 2
Range 32768 N/Min/Max/Mean/Zero 3225000 -553 -273 -378 0
Pressure sensor 2 (2)
X-POS/Y-POS/CAL/DIM 0 0 4.9811*x + 0.56611
I would like to end up with the value "4.9681" and "-0.30715".
Any suggestions on how to make it possible to read these values?

Best Answer

The brute-force way...
>> fmt='%*s %*f %*f %f*x + %f';
>> fid=fopen('lars.txt','r');
>> cell2mat(textscan(fid,fmt,'headerlines',3,'collectoutput',true))
ans =
4.9811 0.5661
Place in a loop either counted or
while ~feof(fid)
...
and concatenate results. If file is large so dynamic reallocation begins to hurt, preallocate a large array first and test for overflow...