opening two files within a function

hello! i need to open two files within a function, but it doesn't work. i can open one file - no problem, but when i try to open an other it says:
??? Error using ==> fgetl at 44 Invalid file identifier. Use fopen to generate a valid file identifier.
Error in ==> fileopentest at 18 zahl = str2num(fgetl(fid2));
i've tried to close the first file, i've tried to use the full path of the second file, its allways the same message i get. can anybody please help?

 採用された回答

Walter Roberson
Walter Roberson 2013 年 5 月 29 日

0 投票

Use the two-output form of fopen:
[fid2, message2] = fopen(....);
if fid2 < 0
disp(['open #2 failed because: ', message2])
end

3 件のコメント

Fedor
Fedor 2013 年 5 月 29 日
it says: open #2 failed because: No such file or directory thats strange, because the first file is in the same directory as the second and the first file opens.
Walter Roberson
Walter Roberson 2013 年 5 月 29 日
We will need code.
Fedor
Fedor 2013 年 5 月 29 日
ok i figured it out, funny story: i was opening the second file with the name i've got from the first. so i wrote in my first file: 'File.dat' naturally the string i get from that is ''File.dat'' :D

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

その他の回答 (0 件)

カテゴリ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by