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:
inporting a very large string file

Subject: inporting a very large string file

From: Navin

Date: 1 Aug, 2013 13:21:07

Message: 1 of 10

Hello,
I have a txt file which is that contains a very long string~ 1000000 characters, with no spaces. Using all of the common import functions textscan, fscanf etc. limits my input to only 2500 characters.
Is there any way that I could import all those characters? Thanks in advance.

Subject: inporting a very large string file

From: dpb

Date: 1 Aug, 2013 13:46:54

Message: 2 of 10

On 8/1/2013 8:21 AM, Navin wrote:
> Hello,
> I have a txt file which is that contains a very long string~ 1000000
> characters, with no spaces. Using all of the common import functions
> textscan, fscanf etc. limits my input to only 2500 characters.
> Is there any way that I could import all those characters? Thanks in
> advance.

I've never heard of such a limit on text files--demonstrate how you're
doing this that you run into such limits.

Alternatively, read the whole file as character array...

fid = fopen('filename');
F = fread(fid, '*char')';

--

Subject: importing a very large string file

From: Navin

Date: 1 Aug, 2013 14:07:07

Message: 3 of 10

Hey,
Thanks for the reply. My program is almost the same-
fid=fopen('my.txt');
C = fscanf(fid, '%s');
fclose(fid);
length(C)
then length(C) returns a value of 2500.
But, it returned the same when I used fread.
Thanks
 

Subject: importing a very large string file

From: dpb

Date: 1 Aug, 2013 14:28:14

Message: 4 of 10

On 8/1/2013 9:07 AM, Navin wrote:
> Hey,
> Thanks for the reply. My program is almost the same-
> fid=fopen('my.txt');
> C = fscanf(fid, '%s');
> fclose(fid);
> length(C)
> then length(C) returns a value of 2500.
> But, it returned the same when I used fread.
> Thanks

Then in all likelihood the 2501st value in the file 'my.txt' is char(0)

--

Subject: importing a very large string file

From: Steven_Lord

Date: 1 Aug, 2013 14:29:26

Message: 5 of 10



"Navin " <navinsingh.itbhu@gmail.com> wrote in message
news:ktdq2b$aoo$1@newscl01ah.mathworks.com...
> Hey,
> Thanks for the reply. My program is almost the same-
> fid=fopen('my.txt');
> C = fscanf(fid, '%s');
> fclose(fid);
> length(C)
> then length(C) returns a value of 2500.
> But, it returned the same when I used fread.

http://www.mathworks.com/help/matlab/ref/fscanf.html

The %s format specifier is designed to "Read series of characters, until
find white space."

So my guess is that character 2501 in your file is a while space character.
I'm not entirely certain what definition of white space FSCANF uses, but
it's probably similar to the one used by ISSPACE:

http://www.mathworks.com/help/matlab/ref/isspace.html

and the definition of wspace used by ISSTRPROP:

http://www.mathworks.com/help/matlab/ref/isstrprop.html?searchHighlight=wspace

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: importing a very large string file

From: Navin

Date: 1 Aug, 2013 14:48:24

Message: 6 of 10

Well, it happens for different files of the same type(filled with continuous characters) that I have, and all types of functions that I used. I have even tried to use 'Import data' from menu option and it creates a string of 2500 characters. I have uploaded that text file for testing this out.
http://www.sendspace.com/file/j2bq5a
Thanks

Subject: importing a very large string file

From: dpb

Date: 1 Aug, 2013 16:49:00

Message: 7 of 10

On 8/1/2013 9:29 AM, Steven_Lord wrote:
...

> So my guess is that character 2501 in your file is a while space
> character. I'm not entirely certain what definition of white space
> FSCANF uses, but it's probably similar to the one used by ISSPACE:
...

Ah, good catch! Isn't only the char(0) but a string.

But, that shouldn't have stopped the fread() which is what gave me the
idea that it was it. Of course, the actual attempt for that wasn't
shown only said it returned same length.

--

Subject: importing a very large string file

From: dpb

Date: 1 Aug, 2013 16:50:40

Message: 8 of 10

On 8/1/2013 9:48 AM, Navin wrote:
> Well, it happens for different files of the same type(filled with
> continuous characters) that I have, and all types of functions that I
> used. I have even tried to use 'Import data' from menu option and it
> creates a string of 2500 characters. I have uploaded that text file for
> testing this out.
> http://www.sendspace.com/file/j2bq5a
> Thanks

More simpler would be to look at the file w/ a binary code viewer or use
the stream read as character and look at the content. How,
specifically, did you try that?

--

Subject: importing a very large string file

From: dpb

Date: 1 Aug, 2013 18:46:07

Message: 9 of 10

On 8/1/2013 11:50 AM, dpb wrote:
> On 8/1/2013 9:48 AM, Navin wrote:
>> Well, it happens for different files of the same type(filled with
>> continuous characters) that I have, and all types of functions that I
>> used. I have even tried to use 'Import data' from menu option and it
>> creates a string of 2500 characters. I have uploaded that text file for
>> testing this out.
>> http://www.sendspace.com/file/j2bq5a
>> Thanks
>
> More simpler would be to look at the file w/ a binary code viewer or use
> the stream read as character and look at the content. How, specifically,
> did you try that?

I did even go but all I got was into a seemingly endless loop of trying
to download what appeared to be some software download manager instead
of just the text file... :(

--

Subject: importing a very large string file

From: TideMan

Date: 1 Aug, 2013 19:49:38

Message: 10 of 10

On Friday, August 2, 2013 2:48:24 AM UTC+12, Navin wrote:
> Well, it happens for different files of the same type(filled with continuous characters) that I have, and all types of functions that I used. I have even tried to use 'Import data' from menu option and it creates a string of 2500 characters. I have uploaded that text file for testing this out.
>
> http://www.sendspace.com/file/j2bq5a
>
> Thanks

Try this:
fid=fopen('myfile.txt','rt');
str=fscanf(fid,'%c');

Now, str will contain everything, including carriage control characters.

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