Invalid File Identifer - Help

2 ビュー (過去 30 日間)
Brett
Brett 2012 年 12 月 4 日
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 件のコメント
Brett
Brett 2012 年 12 月 4 日
Directory problem. Fixed!

サインインしてコメントする。

採用された回答

Sean de Wolski
Sean de Wolski 2012 年 12 月 4 日
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 件のコメント
Brett
Brett 2012 年 12 月 4 日
It is -1... whatever that means... :P
Sean de Wolski
Sean de Wolski 2012 年 12 月 5 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSearch Path についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by