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.

采纳的回答

Walter Roberson
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 CenterFile Exchange 中查找有关 String 的更多信息

产品


版本

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by