![]() ![]() Which I believe would preserve my 10-character field width This function is called within a callback that is activated when I press a button in my GUI which then collects a number of doubles and writes them using sprintf and passing the resulting string to the function below to trim trailing zeros, however the function doesn't always work on the variables passed for some reason.Īnd then I would print strout to the file as: ![]() One thing I tried was writing each number to a string variable using the '%#-10f' format specification, and then passing the resulting string to the function shown below, which uses regular expressions to trim trailing zeros, but for some reason, its not working on some numbers. This is a very complicated GUI and I am getting caught up in this detail of writing the output format I want. It is beyond me why matlab makes formatting so problematic. I do NOT want to use something like '%#-10.3f' because I may have a precision more than three digits past the decimal point, yet still occupy a 10-character or less width field, with a number such as -0.0199 (which by the way will print as left-justified -0.019900 giving me two redundant trailing zeros I do not want to print). This is driving me crazy that you cannot control field width in the fprintf. For example, I want to print the number 138000.0 to a field of no more than 10-character width, but matlab fprintf prints it as:ġ38000.000000 and auto-expanding the field width to 13 characters despite my using the format specification '%#-10f', which should left-justify in a field width of 10 characters. the matlab fprintf statement automatically expands the size of my field width beyond 10 characters to print 6 decimals past the decimal place, messing up the output file format. I do not want the trailing zeros is more than three digits (i.e. As a result, when the value of the number before the decimal point is around The problem that I have is matlab insists in writing these numbers with 6 digits past the decimal point, including unnecessary trailing zeros. The FORTRAN program has very strict limitations on its input, so when writing the output file from my GUI I have uses fprintf statements to write floating point numbers in a 10 character width field, left justified. I have been writing a GUI to input data for a second program (old program written in FORTRAN).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |