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:
textscan problem

Subject: textscan problem

From: Naftali Herscovici

Date: 18 May, 2011 15:38:03

Message: 1 of 6

Hello,
I need to read in EXACTLY the data format as in the Matlab example (when I do help textscan)

I just copied and paste:

matlab code:

fid = fopen('mydata.dat');
C = textscan(fid, '%s%s%f32%d8%u%f%f%s%f');
fclose(fid);


data file:

Sally Level1 12.34 45 1.23e10 inf Nan Yes 5.1+3i
Joe Level2 23.54 60 9e19 -inf 0.001 No 2.2-.5i
Bill Level3 34.90 12 2e5 10 100 No 3.1+.1i

it does not work.

Am I missing something?

Thanks

Tuli

Subject: textscan problem

From: Florin Neacsu

Date: 18 May, 2011 16:38:03

Message: 2 of 6

"Naftali Herscovici" wrote in message <ir0p4r$qg9$1@newscl01ah.mathworks.com>...
> Hello,
> I need to read in EXACTLY the data format as in the Matlab example (when I do help textscan)
>
> I just copied and paste:
>
> matlab code:
>
> fid = fopen('mydata.dat');
> C = textscan(fid, '%s%s%f32%d8%u%f%f%s%f');
> fclose(fid);
>
>
> data file:
>
> Sally Level1 12.34 45 1.23e10 inf Nan Yes 5.1+3i
> Joe Level2 23.54 60 9e19 -inf 0.001 No 2.2-.5i
> Bill Level3 34.90 12 2e5 10 100 No 3.1+.1i
>
> it does not work.
>
> Am I missing something?
>
> Thanks
>
> Tuli

Hi,

What do you mean it does not work? Do you get an error? If so, what is that error?

Regards,
Florin

P.S. it works fine for me

Subject: textscan problem

From: Naftali Herscovici

Date: 18 May, 2011 17:00:05

Message: 3 of 6

I get this error

??? Error using ==> textscan
Invalid file identifier. Use fopen to generate a valid file identifier.

Error in ==> test at 3
C = textscan(fid, '%s%s%f32%d8%u%f%f%s%f');

Subject: textscan problem

From: dpb

Date: 18 May, 2011 17:19:03

Message: 4 of 6

On 5/18/2011 12:00 PM, Naftali Herscovici wrote:
> I get this error
>
> ??? Error using ==> textscan
> Invalid file identifier. Use fopen to generate a valid file identifier.
>
> Error in ==> test at 3
> C = textscan(fid, '%s%s%f32%d8%u%f%f%s%f');

The problem isn't textscan() it's that fopen failed (or you didn't call it).

If the former, use the optional output version to see what, specifically
the error message returned is. If the latter, well...

doc fopen

--

Subject: textscan problem

From: Florin Neacsu

Date: 18 May, 2011 17:20:05

Message: 5 of 6

"Naftali Herscovici" wrote in message <ir0tul$dbd$1@newscl01ah.mathworks.com>...
> I get this error
>
> ??? Error using ==> textscan
> Invalid file identifier. Use fopen to generate a valid file identifier.
>
> Error in ==> test at 3
> C = textscan(fid, '%s%s%f32%d8%u%f%f%s%f');

Hi,

After you do
>fid=fopen('mydata.dat');

What do you get ? If fid=-1 that means there is a problem with the file identifier which could result from a wrong path to the file. Is you file in the current directory ? Are you providing the correct path ?

Florin

Subject: textscan problem

From: Steven_Lord

Date: 18 May, 2011 19:13:27

Message: 6 of 6



"Florin Neacsu" <fneacsu2@gmail.com> wrote in message
news:ir0v45$h0k$1@newscl01ah.mathworks.com...
> "Naftali Herscovici" wrote in message
> <ir0tul$dbd$1@newscl01ah.mathworks.com>...
>> I get this error
>>
>> ??? Error using ==> textscan
>> Invalid file identifier. Use fopen to generate a valid file identifier.
>>
>> Error in ==> test at 3
>> C = textscan(fid, '%s%s%f32%d8%u%f%f%s%f');
>
> Hi,
>
> After you do
>>fid=fopen('mydata.dat');
>
> What do you get ? If fid=-1 that means there is a problem with the file
> identifier which could result from a wrong path to the file. Is you file
> in the current directory ? Are you providing the correct path ?

If fid is in fact -1, modify your call to FOPEN to call it with two output
arguments and look at the message returned as the second output for more
information about why opening the file failed.

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

Tags for this Thread

No tags are associated with 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