Invalid File Identifer - Help

2 visualizzazioni (ultimi 30 giorni)
Brett
Brett il 4 Dic 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

Risposta accettata

Sean de Wolski
Sean de Wolski il 4 Dic 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 Commenti
Brett
Brett il 4 Dic 2012
It is -1... whatever that means... :P
Sean de Wolski
Sean de Wolski il 5 Dic 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Search Path in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by