Filter löschen
Filter löschen

Invalid File Identifer - Help

2 Ansichten (letzte 30 Tage)
Brett
Brett am 4 Dez. 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 Kommentar
Brett
Brett am 4 Dez. 2012
Directory problem. Fixed!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Search Path finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by