Convert string to txt
48 次查看(过去 30 天)
显示 更早的评论
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 个评论
Ameer Hamza
2020-4-2
编辑:Ameer Hamza
2020-4-5
You should not run save('A.txt'). It is useless for your problem.
回答(1 个)
Maadhav Akula
2020-4-5
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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!