Character limit in using fwrite?

21 vues (au cours des 30 derniers jours)
Sam
Sam le 21 Déc 2013
Commenté : Sam le 22 Déc 2013
I have a char string that I am trying to write to a .NET file, which is somewhat similar to a .txt file. However, I've noticed that strings above a certain length (seems to be around 100 characters) return the error message
Error using fwrite
Invalid file identifier. Use fopen to generate a valid file identifier.
Strings under this length write to my file directory just fine.
This is my first time using these MATLAB data writing commands, so I'm just using the basic file writing commands right now:
clear fileID
fileID = fopen(text, 'w');
fwrite(fileID, text);
fclose(fileID);
where text is my character string. How can I resolve this issue for these longer char strings?
Also, two somewhat related questions, if you don't mind:
(1) how do I write this string to a particular file extension, like .NET?
(2) is there a way to specify a name for the file that I'm writing to?
Thanks!

Réponse acceptée

Image Analyst
Image Analyst le 21 Déc 2013
Modifié(e) : Image Analyst le 21 Déc 2013
text is a built in function name. That could be your problem. Pick a different name, and use your actual string variable name instead of text.
What is fileID? Is it -1? If so, you were unable to write to the file, possibly because of permission denials or the disk is full or something else.
  13 commentaires
Walter Roberson
Walter Roberson le 21 Déc 2013
filename = ['test_', datestr(now, 'yyyymmddHHMMFFF'), '.txt'];
or equivalently,
filename = sprintf('test_%s.txt', datestr(now, 'yyyymmddHHMMFFF'));
Sam
Sam le 22 Déc 2013
Got it. Thanks very much for your help, Walter and Image Analyst!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Low-Level File I/O 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