Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: reading from a text file
Date: Mon, 18 May 2009 15:15:03 +0000 (UTC)
Organization: Universit&#228;tsSpital Z&#252;rich
Lines: 66
Message-ID: <guru1n$gsh$1@fred.mathworks.com>
References: <gurtb5$h3$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1242659703 17297 172.30.248.35 (18 May 2009 15:15:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 18 May 2009 15:15:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11
Xref: news.mathworks.com comp.soft-sys.matlab:540746


"omar " <ouzizo@gmail.com> wrote in message <gurtb5$h3$1@fred.mathworks.com>...
> guys i am making a project and there is a part which involves reading data from 1500 text files, so i have to find a way to automate this process.
> the text files look like this:
> 
> version: 1
> n_points: 20
> {
> 154.05 102.829
> 223.237 102.829
> 156.589 175.824
> 219.429 173.285
> 129.295 90.7684
> 177.536 92.0379
> 199.752 94.5768
> 247.992 91.4031
> 125.487 107.272
> 138.816 105.367
> 169.284 103.463
> 209.908 103.463
> 237.202 106.002
> 253.07 107.906
> 188.326 132.661
> 177.536 140.913
> 199.752 141.548
> 187.692 171.381
> 187.057 190.423
> 186.422 224.065
> }
> 
> I have to read the numbers in the two columns such that each two numbers in the same line are read into a 2x1 matrix, which results in 20 matrices(according to the number of lines) each containing two elements.
> 
> Any links, explanation, or documentation would be appreciated.
> thanks in advance

one of the solutions
- given the file's anatomy as shown above

     fnam='foo.txt';     % <- your file name
     s=textread(fnam,'%n','headerlines',3,'whitespace','}');
     s=reshape(s.',2,[]).'
%{
%    note: format short g!
     s =
       154.05       102.83
       223.24       102.83
       156.59       175.82
       219.43       173.29
       129.29       90.768
       177.54       92.038
       199.75       94.577
       247.99       91.403
       125.49       107.27
       138.82       105.37
       169.28       103.46
       209.91       103.46
        237.2          106
       253.07       107.91
       188.33       132.66
       177.54       140.91
       199.75       141.55
       187.69       171.38
       187.06       190.42
       186.42       224.07
%}

us