How can I vary decimal precision or format in Format Spec dependent on value being written?
1 view (last 30 days)
Show older comments
The specific problem that prompted this is a vector of data containing data values and NoData values that I want to write to a text file. A short example might be:
-9999.0000 550.8359 -9999.0000 ...
I want to write this to a text file so that it reads:
-9999 550.8359 -9999
Any ideas to do this using the FormatSpec syntax (e.g. %u vs. %.4d) such that the correct format is applied to the correct value? I'm looking for a way to vary the specifier overall and to vary specific parts of the specifier (like the precision value or field width) based on the value being written.
I had thought to write each sequentially using a loop but I would prefer something more efficient!
Thanks for any ideas.
0 Comments
Answers (0)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!