0

I have a text file which consists:

// MATLAB to process this file
ModelName : Matlab1
PerturbationId : 0
X1X2_001 : 0.270971584968118
X1X2_002 : 0.55555
OBJECTF : ?
NumberOfRuns : 25
SimulationId : 0

What I want to do is to get 0.270971584968118 and 0.55555 out of it, the important thing is that the file is not the same after each run, I mean the name of X1X2 may change (but there is always 001 and 002 at the end). also the values may change (0.270971584968118 and 0.55555). I used textscan but since the file has not specific format (values are not separated by tab, and they are not tabular) it was not useful.

Thanks

Daniel
  • 36,610
  • 3
  • 36
  • 69
masoud
  • 1

1 Answers1

0

OKAY. So the straightforward way says:

%//read in file
fileID = fopen('your.txt')
C = textscan(fileID,'%s %s','Delimiter',':');  %// delimit on ':'
%//you are looking for C{2} the second row of the cell.
value1 = cell2mat(C{2}(4,:));
>> 0.270971584968118
value2 = cell2mat(C{2}(5,:));
>> 0.55555

So this is quite straight forward and easy to understand, but it is not the most efficient way. For efficiency, look for alternatives to cell2mat.

rayryeng
  • 102,964
  • 22
  • 184
  • 193
GameOfThrows
  • 4,510
  • 2
  • 27
  • 44