Convert string to txt
Mostra commenti meno recenti
I have a 4x1 string array, how can i write it and save it as a txt file? Not sure if i did it correctly.
A=(4x1) string array
fid = fopen('A.txt','wt');
fprintf(fid, '%s\n',A);
fclose(fid);
5 Commenti
Rik
il 2 Apr 2020
Can't you open the resulting file with notepad (or even the Matlab editor) to check the output? I would expect this code to work as intended. Why do you think there is a problem?
Jose Grimaldo
il 2 Apr 2020
Modificato: Jose Grimaldo
il 2 Apr 2020
Ameer Hamza
il 2 Apr 2020
What is the value matrix A?
Jose Grimaldo
il 2 Apr 2020
Ameer Hamza
il 2 Apr 2020
Modificato: Ameer Hamza
il 5 Apr 2020
You should not run save('A.txt'). It is useless for your problem.
Risposte (1)
Maadhav Akula
il 5 Apr 2020
Hi,
I think you are getting that extra line because of the '\n' escape character. You can try the following code :
fid = fopen('A.txt','w');
fprintf(fid, '%s\n',A(1:end-1));
fprintf(fid,'%s',A(end));
fclose(fid);
Hope this Helps!
Categorie
Scopri di più su File Operations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!