string to text file
显示 更早的评论
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 个评论
dpb
2019-3-8
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
2019-3-8
Bob Thompson
2019-3-8
What commands did you use to create the actual text file?
dpb
2019-3-8
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
2019-3-8
dpb
2019-3-8
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
Image Analyst
2019-3-9
What's all this? Did you see any of the the compact Answers below?
采纳的回答
更多回答(2 个)
Bob Thompson
2019-3-8
0 个投票
1 个评论
per isakson
2019-3-8
There is no section on exporting a string array.
Image Analyst
2019-3-8
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

