How do I format writecell
조회 수: 13 (최근 30일)
이전 댓글 표시
Hello
I am writing heterogeneous data to a text file using writecell. It's working great except I can't figure out how to format the date.
Final_Results = {'**iterations**',output.iterations;
'**sum of squares of residual**',sumsqres;
'**optimized parameters**',varsol.r;
' ',varsol.N_one;
'**R2 for each data set**',R2;
'**R2 total**',R2_Total};
writecell(Final_Results,strcat(FileP,'Fitting Results - opt y0.txt'));
My .txt fill looks something like this:
**iterations**,0,,,,,,,,,,,,
**sum of squares of residual**,0.0333663467975929,,,,,,,,,,,,
**optimized parameters**,105.053698018503,135.25921779908,4997.10850254932,18.3319033386186,,,,,,,,,
,0.0100857216696102,0.0131223532382211,0.0161616821643856,0.020697637863773,0.0243621782338721,0.0281775537074196,0.0339562520545579,0.0456442526700484,0.0477440936132656,0.0596823396528703,0.0617637362618315,0.0735389933356788,0.0866238132326763
**R2 for each data set**,0.999999770632282,0.99999813262161,0.999996316567805,0.999992979556768,0.999991008553711,0.999983081619234,0.999979843221376,0.99995399886751,0.999959579532182,0.999928567513284,0.999893329838681,0.999533422355992,0.999649427384684
**R2 total**,0.999912266020394,,,,,,,,,,,,
I would like to control the data format such as putting it in %0.6e exponential form or something. Also I would like to get rid of the etra commas. Or is there a good reason to have the extra commas?
Any help would be appreciated.
댓글 수: 0
채택된 답변
Walter Roberson
2020년 4월 14일
you can use compose() to convert the numeric values to cell array of character vectors using whatever format you want.
The extra commas are required by the csv standard https://tools.ietf.org/html/rfc4180
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 String에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!