Floating point numeric display vs engineering / exponential notation

I'm importing data from csv files. In that data I have mixed text and floating point numbers. How can I get MatLab to display floating point numbers in the original format as opposed to the engineering/exponential format ?
I find it a lot easier to read 1326.949233 than I do 1.326949233000000e+03 for instance.
TIA, Mal

Answers (1)

The format in which the numbers are printed is not affected by the source (in this case, a CSV file). That is, as long as you read the CSV file into a double array, MATLAB will store the numbers internally as doubles and will print them according to one of it's standard printing formats. Type
help format
to see the options and an explanation of each one.
If you want to preserve the formatting that is used in the CSV file, you need to read the file as text.

4 Comments

Yep - I tried format however it does not appear to support non-exponential notation. So if I read the data in as text, can I then calculate with that textual representation of the number ?
For what it's worth, I brought the data in using the [num,Text,Raw]=xlsread(filename)command.
You cannot perform mathematical operations on the numbers represented as strings--at least not without serious contortions.
You should read the data as a numeric data type (such as double) and perform all your calculations on that type. When you display the number, you can control the display format more carefully by using fprintf.
Try for example,
A = 1000*randn(4,3) % prints to command window in default format
fprintf([repmat('% 25.15f',1,size(A,2)) '\n'],A) % prints in fixed-point format
Note that you need to adjust the minimum field width (25 in the case above) if A has larger values. Compare:
fprintf([repmat('% 25.15f',1,size(A,2)) '\n'],100000*A) % prints in fixed-point format
fprintf([repmat('% 30.15f',1,size(A,2)) '\n'],100000*A) % prints in fixed-point format
Good luck!
Brian
Actually you can get some robustness to large numbers by adding spaces in the format string, though the decimals still may not line up if the number of digits to the left of the decimal is too large:
fprintf([repmat('% 25.15f ',1,size(A,2)) '\n'],100000*A) % prints in fixed-point format

Sign in to comment.

Categories

Products

Asked:

on 18 Jan 2013

Community Treasure Hunt

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

Start Hunting!