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
Matthew Tyler Jeffries
2019년 3월 9일
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!

