Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
textread - recall last position

Subject: textread - recall last position

From: supandey@yahoo.com

Date: 11 Feb, 2009 19:22:16

Message: 1 of 7

Is it possible for textread to read from the last poistion it read
from? For file -

%test
10,20,30
40,50,60

I can read via:

[x1,x2,x3] = textread('t.txt','%d%d%d',
1,'delimiter',',','commentstyle','matlab');
[y1,y2,y3] = textread('t.txt','%d%d%d',
1,'delimiter',',','commentstyle','matlab', 'headerlines', 2);

Is there another solution which avoids using headerlines? Something
like fseek/ftell?

Thanks,
Sanjeev

Subject: textread - recall last position

From: NZTideMan

Date: 11 Feb, 2009 19:25:20

Message: 2 of 7

On Feb 12, 8:22=A0am, supan...@yahoo.com wrote:
> Is it possible for textread to read from the last poistion it read
> from? For file -
>
> %test
> 10,20,30
> 40,50,60
>
> I can read via:
>
> [x1,x2,x3] =3D textread('t.txt','%d%d%d',
> 1,'delimiter',',','commentstyle','matlab');
> [y1,y2,y3] =3D textread('t.txt','%d%d%d',
> 1,'delimiter',',','commentstyle','matlab', 'headerlines', 2);
>
> Is there another solution which avoids using headerlines? Something
> like fseek/ftell?
>
> Thanks,
> Sanjeev

Use textscan for this

Subject: textread - recall last position

From: us

Date: 11 Feb, 2009 19:40:17

Message: 3 of 7

supandey@yahoo.com
> %test
> 10,20,30
> 40,50,60
> I can read via:
> [x1,x2,x3] = textread('t.txt','%d%d%d',
> 1,'delimiter',',','commentstyle','matlab');
> [y1,y2,y3] = textread('t.txt','%d%d%d',
> 1,'delimiter',',','commentstyle','matlab', 'headerlines', 2);
>
> Is there another solution which avoids using headerlines...

one of the solutions

     fnam='t.txt'; % <- your text file...
     s=textread(fnam,'%s','delimiter','\n');
     d=cellfun(@(x) sscanf(x,'%g,').',s(2:end),'uni',false);
     d{1:2} % <- or d{:}
%{
% ans =
          10 20 30
% ans =
          40 50 60
%}
% it comes with the benefit of NOT having too many vars in your ws...

us

Subject: textread - recall last position

From: supandey@yahoo.com

Date: 11 Feb, 2009 21:33:09

Message: 4 of 7

On Feb 11, 1:25=A0pm, NZTideMan <mul...@gmail.com> wrote:
> On Feb 12, 8:22=A0am, supan...@yahoo.com wrote:
>
>
>
>
>
> > Is it possible for textread to read from the last poistion it read
> > from? For file -
>
> > %test
> > 10,20,30
> > 40,50,60
>
> > I can read via:
>
> > [x1,x2,x3] =3D textread('t.txt','%d%d%d',
> > 1,'delimiter',',','commentstyle','matlab');
> > [y1,y2,y3] =3D textread('t.txt','%d%d%d',
> > 1,'delimiter',',','commentstyle','matlab', 'headerlines', 2);
>
> > Is there another solution which avoids using headerlines? Something
> > like fseek/ftell?
>
> > Thanks,
> > Sanjeev
>
> Use textscan for this- Hide quoted text -
>
> - Show quoted text -

Unfortunately my version of Matlab (v6.5) does not have textscan.

Subject: textread - recall last position

From: Andres

Date: 11 Feb, 2009 22:00:19

Message: 5 of 7

supandey@yahoo.com wrote in message <b9f14884-002b-4cfe-b5ee-751ed6a1c3e3@w39g2000prb.googlegroups.com>...
[..]
>
> Unfortunately my version of Matlab (v6.5) does not have textscan.

You may give txt2mat from the file exchange a try - look at the doc for the 'FilePos' argument. It is compatible with v6.5.

Subject: textread - recall last position

From: us

Date: 11 Feb, 2009 22:23:02

Message: 6 of 7

supandey@yahoo.com
> Unfortunately my version of Matlab (v6.5) does not have textscan...

well, did you try other solutions that were presented to you...

us

Subject: textread - recall last position

From: supandey@yahoo.com

Date: 12 Feb, 2009 16:08:50

Message: 7 of 7

On Feb 11, 4:23=A0pm, "us " <u...@neurol.unizh.ch> wrote:
> supan...@yahoo.com
>
> > Unfortunately my version of Matlab (v6.5) does not have textscan...
>
> well, did you try other solutions that were presented to you...
>
> us

I did not try this yet:

     fnam=3D't.txt'; % <- your text file...
     s=3Dtextread(fnam,'%s','delimiter','\n');
     d=3Dcellfun(@(x) sscanf(x,'%g,').',s(2:end),'uni',false);
     d{1:2} % <- or d{:}

The issue is that the file I want to read has about 40 million rows in
it (each row has 200 variables). I think the

s=3Dtextread(fnam,'%s','delimiter','\n');

will read the whole file in and than run into memory overflow
problems. Hence my need to read the file in chunks.

Thanks,
Sanjeev

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us