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
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com