fprintf doesn't print anything

25 vues (au cours des 30 derniers jours)
Bob Thompson
Bob Thompson le 6 Août 2018
Commenté : Bob Thompson le 6 Août 2018
I am trying to write some data to a file using the fprintf command, but when I run the command the file remains blank. I don't receive any errors, and I cannot identify anything unusual happening.
A = rand(10,7);
fid = fopen('filename.txt','w');
fprintf(fid,'%-6.3d %-12.8d %-12.8d %-10.8d %-10.8d %-10.8d %-4.0d\n',A);
fclose fid
I've used nearly the exact same fprintf line (just changed variable names) before in a different script and it worked fine so I don't understand why it's not printing anything here.

Réponse acceptée

Image Analyst
Image Analyst le 6 Août 2018
Modifié(e) : Image Analyst le 6 Août 2018
I just tried this:
A = rand(10,7);
fid = fopen('filename.txt','wt');
fprintf(fid,'%-6.3d %-12.8d %-12.8d %-10.8d %-10.8d %-10.8d %-4.0d\n', A);
fclose(fid);
winopen('filename.txt'); % Only if using Windows!
and it worked fine for me. You might change 'w' to 'wt' but it worked regardless.
  1 commentaire
Bob Thompson
Bob Thompson le 6 Août 2018
In all honestly, I wasn't sure if it was going to be repeatable, since it seemed to run fine in my other code. That's part of why I was so confused and needed to ask.
Either way, using 'wt' did work, so thanks.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by