Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: PLEASE help to extract data of text file into variables
Date: Wed, 15 Oct 2008 07:54:02 +0000 (UTC)
Organization: Pierburg GmbH
Lines: 23
Message-ID: <gd47iq$ql7$1@fred.mathworks.com>
References: <gd30v8$2un$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 1224057242 27303 172.30.248.37 (15 Oct 2008 07:54:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 15 Oct 2008 07:54:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 872224
Xref: news.mathworks.com comp.soft-sys.matlab:495261


"Diego Zegarra" <diegozbb@gmail.com> wrote in message <gd30v8$2un$1@fred.mathworks.com>...
> Guys please I need help reading a text file like this. I have posted a couple questions regarding this but I dont find a solution for this. I have been trying to use fscanf, textscan, textread, txt2mat, etc and I cannot get them to work.


Hi Diego,
this is at least the third thread you have opened for the same problem - so it is hard to keep track of it. Remember there are people from different time zones who are not checking the newsgroup every few minutes.

Now here's some code example with txt2mat - it is uncommented, but hopefully quite understandable. Just note that I created a cell array with ST{1}..ST{n} instead of separate variables ST_1..ST_n, and I would recommend this to you, too. I think there are also FAQ pages about this topic.
Hth,
Andres


% get matrices A, PT and ST{i} from text file
data = txt2mat('c:\filename.txt',0);
A = data([1,2],1).';
nextRowIndex = 3;
PT = data(nextRowIndex+(1:A(2)), 1:A(1));

ST = cell(A(1),1);
for idx = 1:A(1)
    nextRowIndex = nextRowIndex + 1 + A(2);
    ST{idx} = data(nextRowIndex+(1:A(2)), 1:A(2));
end