How do I format writecell

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.

 Risposta accettata

Walter Roberson
Walter Roberson il 14 Apr 2020

0 voti

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

Più risposte (0)

Categorie

Prodotti

Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by