Got Questions? Get Answers.
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:
error invalid identifier

Subject: error invalid identifier

From: Leah

Date: 9 Jul, 2012 21:01:12

Message: 1 of 2

When I start my program i get an error message saying ???
Error using ==> textscan
Invalid file identifier. Use fopen to generate a valid file identifier.

Error in ==> abc at 23
    for i=1:18 hdr=textscan(fid,'%s %*[^\n]',1); end
for the program

function spec = abc(filelist);

filelist='add.txt';
fl = importdata(filelist);

apfile = size(fl,1);
%fid = fopen(file);

bcc = 1024;

spec = zeros(apfile, bcc);

for iFile = 1:nFile
    
    fid = fopen(fl{apfile});
    
       for i=1:18 hdr=textscan(fid,'%s %*[^\n]',1); end
    
    x=textscan(fid,'%d%d','delimiter',',,');
    x = x{:,1};
    
    x = reshape(x,2,bcc);
    spec(apFile,:) = x(2,:);
    
    fclose(fid);
    
end

Subject: error invalid identifier

From: Steven_Lord

Date: 10 Jul, 2012 13:44:34

Message: 2 of 2



"Leah " <strawberriesncream8148@yahoo.com> wrote in message
news:jtfgqo$eg7$1@newscl01ah.mathworks.com...
> When I start my program i get an error message saying ??? Error using ==>
> textscan
> Invalid file identifier. Use fopen to generate a valid file identifier.
>
> Error in ==> abc at 23
> for i=1:18 hdr=textscan(fid,'%s %*[^\n]',1); end
> for the program

*snip*

> fid = fopen(fl{apfile});

Call FOPEN with two outputs. Before using fid, check if it's -1:

http://www.mathworks.com/help/techdoc/ref/fopen.html

"An integer that identifies the file for all subsequent low-level file I/O
operations. If fopen cannot open the file, fileID is -1."

If fid is -1, display the second output:

"A system-dependent error message when fopen cannot open the specified file.
Otherwise, an empty string."

That should help you determine why the attempt to open the file failed.

Then modify your code and/or your system appropriately for your application.

*snip*

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

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