Thread Subject: Can you do this with load?

Subject: Can you do this with load?

From: David Doria

Date: 27 May, 2008 13:07:02

Message: 1 of 3

I have a file like this

1 2 3
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
(etc. 1000's of lines like the previous)

where the first line is shorter than the rest.

Is there a way with load() to say "Its ok, just fill in NaN
for the missing numbers? It just seems better to read this
file with load instead of writing a loop and using fscanf.

Thoughts?

Thanks,

Dave

Subject: Can you do this with load?

From: us

Date: 27 May, 2008 13:21:01

Message: 2 of 3

"David Doria":
<SNIP simple text reader...

> I have a file like this
> 1 2 3
> 1 2 3 4 5 6
> 1 2 3 4 5 6
> 1 2 3 4 5 6
> 1 2 3 4 5 6

one of the solutions

     fnam='foo.txt'; % your file name...
     nc=6;
     fmt=repmat('%n',1,nc);
     clear m;
     [m{1:nc}]=textread(fnam,fmt,'emptyvalue',nan);
     m=cat(2,m{:});
     disp(m)
%{
     1 2 3 NaN NaN NaN
     1 2 3 4 5 6
     1 2 3 4 5 6
     1 2 3 4 5 6
     1 2 3 4 5 6
%}

us

Subject: Can you do this with load?

From: David Doria

Date: 27 May, 2008 13:45:02

Message: 3 of 3

WOW!!! It went from 150 seconds to 0.45 seconds to read the
file!!!

What does textread do that makes it so fast? This is MUCH
faster than even reading the file in c++!!

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
code us 27 May, 2008 09:25:05
textread us 27 May, 2008 09:25:05
cat us 27 May, 2008 09:25:05
rssFeed for this Thread

Contact us at files@mathworks.com