Invalid File Identifer - Help

2 vues (au cours des 30 derniers jours)
Brett
Brett le 4 Déc 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
  1 commentaire
Brett
Brett le 4 Déc 2012
Directory problem. Fixed!

Connectez-vous pour commenter.

Réponse acceptée

Sean de Wolski
Sean de Wolski le 4 Déc 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 commentaires
Brett
Brett le 4 Déc 2012
It is -1... whatever that means... :P
Sean de Wolski
Sean de Wolski le 5 Déc 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Search Path dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by