Saturday 15 August 2015

number formatting - Format Matlab data to only have digits after the decimal place -


I used dlmwrite to output some data to the following form:

   -1.7693255974E + 00, -9.7742420654 E-04, 2.1528647648 E-04, -1.4866241234 E00 What I really want is the following format:  
 < Code> -. 1769325597 E +0, -9 774242065 E-04, .2152864764 E-04, -14486624123 E + 00  

Before each number a place is required, after an indication, If the number is negative, and the number format comma has been divided into exponential form for 10 significant digits.

Only if Matlab is not able to write this format (-1769325597E + 00), so what is specifically called it so that I can find other ways to solve my problem?

While it seems morally wrong, using a regular expression to move the decimal point can do. What is this function

  myFormat = @ (x) regexprep (sprintf ('% .9e', 10 * x), '(\ d) \.', '. $ 1') ;  

In order to move the point, the input value is 10 times before formatting. Example: myFormat (-pi ^ 7) returns - 3020293228e + 04 .

The above mentioned tasks for individual numbers. The following version is also capable of formatting the ormes, providing a comma separator. Removes a comma behind the second regexprep

  myArrayFormat = @ (x) regexprep (regexprep ('% .9E,', 10 * x), '(\ d) \.', ' $ 1 '),', $ ',' '); Example:  myArrayFormat (1000 * rand (1,5) -500)  back 

  - 2239749230e + 03, personal For numbers,  myArrayFormat  works equally for ; 1 9 7026769e + 03, .1550 9 0040e + 03, -37373882648e + 03, -3.810023184e + 03  

My format .


No comments:

Post a Comment