MATLAB Writing Strings to File in MATLAB

AI Thread Summary
The user initially attempted to write a string to a .txt file using a method that resulted in unexpected characters appearing in the file. The solution involved using the fopen function with the 'wt' mode to open the file for writing text, followed by fprintf to write the string, and finally closing the file with fclose. This approach successfully resolved the issue of incorrect characters in the output file.
darthxepher
Messages
56
Reaction score
0
Hey,

so i want to write a string to a .txt file and I tried by doing this:

save filename.txt writer

(where writer is the variable containing string)
...
But i get weird char. instead of the string.
Any ideas?
 
Physics news on Phys.org
I solved it with a

fid = fopen(path,'wt');
fprintf(fid,writer);
fclose(fid);


:)
 

Similar threads

Replies
4
Views
1K
Replies
1
Views
2K
Replies
5
Views
2K
Replies
3
Views
1K
Replies
4
Views
3K
Back
Top