Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: read nonuniform text
Date: Tue, 28 Oct 2008 21:52:01 +0000 (UTC)
Organization: CVUT
Lines: 48
Message-ID: <ge81i1$jf6$1@fred.mathworks.com>
References: <ge6nld$1bn$1@fred.mathworks.com> <ge799q$ss$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1225230721 19942 172.30.248.37 (28 Oct 2008 21:52:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 28 Oct 2008 21:52:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1574688
Xref: news.mathworks.com comp.soft-sys.matlab:497715


"Andres" <rantore@werb.deNoRs> wrote in message <ge799q$ss$1@fred.mathworks.com>...
> A suggestion with txt2mat from the file exchange:
> .
> A = txt2mat('file.txt','ReplaceExpr',{{'*','0'},{'PG','1 '}});
> .
> The values in the first column of A, 0 or 1, will indicate whether the numbers were taken from a line starting with '*' or 'PG', respectively. Rows will be padded with NaNs.
> Hth
> Andres

thank you for you answer :]. I will try your advice (not today but tomorrow :]). 

For now I have this code which use function "fgetl()" and then I split line into strings where I convert number in strings to double. I need PGXX number which are converted into number without 'PG' via regular expression.

There is the most important part of my code:

fid = fopen('file.txt');

while ~feof(fid)
  % Read line from file
  newLine = fgetl(fid);
  .
  .
  .
  % Split one string to strings via regular expression
  workLine = regexp(newLine, '([^ \t]*)', 'match');
  .
  .
  .
  % Some lines begining with star (*), so I filter every line and if I catch star (*) I substitude for zero
  if strcmp(newLine(ii),'*')
    SP3data(lineIndex-22,ii) = 0;
  end
  .
  .
  .
  % This part convert "PGXX" number into double number via regular expression
  a = char(workLine(ii));
  aa = regexp(char(a),'([0-9]*)', 'match');
  aaa = char(aa);
  SP3data(lineIndex,ii) = str2double(aaa);
  .
  .
  .
  % This part convert number in string to double
  SP3data(lineIndex-22,ii) = str2double(workLine(ii));
  .
  .
end