print decimal with comma instead of point

13 vues (au cours des 30 derniers jours)
Alessandro Renna
Alessandro Renna le 2 Juin 2013
Hello, I need to save a .txt file with data of a matrix M like
1 1 -52.56 -92.20 28.94
1 2 -22.57 -92.19 28.01
2 1 -39.96 -92.20 44.76
2 2 -12.22 -92.08 33.33
3 1 -22.83 -92.20 55.49
3 2 -0.66 -92.03 35.27
I use this script
fid = fopen('curve_back.txt','wt');
fprintf(fid,'%0.0f %0.0f %0.2f %0.2f %0.2f\n',M');
fclose(fid);
but I'd like to save numbers with comma separator instead of point symbol. Any hint? Thanks.

Réponse acceptée

Matt J
Matt J le 2 Juin 2013
Modifié(e) : Matt J le 2 Juin 2013
Here's one way,
T=strrep(evalc('disp(M)'),'.',',');
fid = fopen('curve_back.txt','wt');
fwrite(fid,T);
  1 commentaire
Alessandro Renna
Alessandro Renna le 2 Juin 2013
Thanks, it works very good

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB 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