string to text file
조회 수: 17 (최근 30일)
이전 댓글 표시
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
채택된 답변
per isakson
2019년 3월 8일
편집: per isakson
2019년 3월 8일
This creates a textfile, which notepadd++ opens.
v1=str(:,1);
v2=str(:,2);
v3=str(:,3);
T = table( v1,v2,v3 );
writetable( T, 'str.csv' )
as does
T = table( str(:,1),str(:,2),str(:,3) );
writetable( T, 'str.csv' )
however, this throws an error
>> writetable( table( str ), 'str.csv' )
Error using writetable (line 142)
Unable to perform assignment because the left and right sides have a different number of
elements.
Better control of the format
%%
cac = str2cell( str );
fid = fopen( 'h:\m\cssm\str.csv', 'w' );
fprintf( fid, '%-24s %-24s %-24s\n', cac{:} );
fclose( fid );
Where (OCR and cleaning)
%%
str = [
"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" ];
댓글 수: 3
추가 답변 (2개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!