Invalid File Identifer - Help

1 view (last 30 days)
Brett
Brett on 4 Dec 2012
My code:
subject_number = input('Subject Number?'); %will prompt for subject number in the command window
filename = ['IntrinsicAttention' num2str(subject_number) '.txt']; %creating the text file name with subject number
fid = fopen(filename, 'w'); %append instead overwrite
fprintf(fid, 'q1col, q2col, q3col, q4col, q1tri, q2tri, q3tri, q4tri,tarmatch, RT') %top header, specifying the variables the columns represent
fprintf(fid, '\n')
This code is supposed to create a text file. When I run it though I get an error "Invalid file identifier. Use fopen to generate a valid file identifier." I think it means it cannot create a directory. Looking at other answers, I tried changing the 'w' value, to 'wt' and 'a+' but that didn't seem to help.
Does anyone have any idea how to fix this?
Thanks, Brett

Accepted Answer

Sean de Wolski
Sean de Wolski on 4 Dec 2012
What is the value of fid?
I'll assume it's negative and you can likely find the explanation in:
doc fopen
I.e. try calling:
[fid,msg] = fopen(blah,'w');
  2 Comments
Brett
Brett on 4 Dec 2012
It is -1... whatever that means... :P
Sean de Wolski
Sean de Wolski on 5 Dec 2012
What did the message say? I would guess one of two things:
  1. You don't have write permissions in that directory.
  2. The file is open by another program (or even by another fid) and thus is locked for writing/editing.

Sign in to comment.

More Answers (0)

Categories

Find more on Search Path in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!