string to text file
Show older comments
Hello,
I have a program that produces a very large string array, and I would like to be able to open it in Notepad++. I tried going into Notepad++ to open my file, but when it opened, it looked like gibberish. How can I convert my matlab string array so I can open it in Notepad++?
Thank you
8 Comments
dpb
on 8 Mar 2019
We'd have to see how you created the file. A small example will serve just as well as a large one....
Matthew Tyler Jeffries
on 8 Mar 2019
Bob Thompson
on 8 Mar 2019
What commands did you use to create the actual text file?
dpb
on 8 Mar 2019
Even better, attach a sample small(ish) sample code/data...as text, not image so somebody can do something with it besides just look...
Matthew Tyler Jeffries
on 8 Mar 2019
dpb
on 8 Mar 2019
Again, it's much easier for folks to have actual code/data to work with rather than generalities and definitely better than images!
There are a number of ways to write string data to a file, but just what, specifically, is dependent upon how you actually created the data.
Matlab has multiple choices; it could be a char() array, a cellstr() array or the new(ish) string() array. Which it is, and how to write it, is dependent upon that.
The image above makes it appear it may be the new string() class; if so, then fprintf is string aware.
See
doc fprintf % for information examples
Matthew Tyler Jeffries
on 9 Mar 2019
Image Analyst
on 9 Mar 2019
What's all this? Did you see any of the the compact Answers below?
Accepted Answer
More Answers (2)
Bob Thompson
on 8 Mar 2019
0 votes
1 Comment
per isakson
on 8 Mar 2019
There is no section on exporting a string array.
Image Analyst
on 8 Mar 2019
Are you using %s instead of %f? Try this - it works!
Results = [
"later ite-DD030" "210801" "210801"
"later ite-DD036" "28160" "28160"
"later ite-DDU7" "127198" "127198"
"later ite-DDC4g" "204186" "204186"
"laterite-DDOSO" "19161" "19161"
"later ite-DDD63" "302210" "302210"
"later ite-DDD68" "258159" "214865"
"later ite-DDDEg" "214865" "231473"
"laterite-DD073" "231473" "203491"
"later ite-DD074" "210801" "210801"
"laterite-DDD81" "28160" "28160"
"later ite-DDDB8" "127198" "127198"
"laterite-DOID8" "204186" "204186"
"laterite-DOIDg" "19161" "19161"
"laterite-DOI IO" "302210" "302210"
"laterite-DOI 12" "258159" "214865"
"laterite-DOI 13" "214865" "231473"
"laterite-DOI 16" "231473" "203491"
"laterite-DOI Ig" "203491" "204186"
"podchrome-DDDOI" "228019" "228019"
"podchrome-DDD02" "208319" "208319"
"podchrome-DDDD3" "4653" "252321"
"podchrome-DDDCL4" "251670" "251670" ];
numRows = size(Results, 1);
filename = fullfile(pwd, 'Results.txt');
fileID = fopen(filename, 'wt');
for row = 1 : numRows
fprintf(fileID, '%s, %s, %s\n', Results(row, 1), Results(row, 2), Results(row, 3));
end
fclose(fileID);
winopen(filename); % Pop open in the default text editor program.
Categories
Find more on Text Data Preparation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
