Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Precision problem with xlsread

251 views
Skip to first unread message

Marat

unread,
Jan 3, 2010, 6:50:04 AM1/3/10
to
I have data such as this in an excel sheet. The number of rows and columns can get get bigger (few hundreds).
0.000000000000 363.548604178313 485.186546083050
363.548604178313 0.000000000000 202.195421560430
485.186546083050 202.195421560430 0.000000000000
891.253733175912 535.522317088653 539.651284812702
1026.191509271050 673.810725723478 677.908273588691

I want process this and for that it needs to be in a matrix with the format and precision preserved. I tried the Import Data GUI utility, which appears to gives me result to 4 decimal places (but when I copy the cell the entire value is present).

I tried xlsread('file.xls'). Below is what I get:
1.0e+003 *

0 0.3635 0.4852
0.3635 0 0.2022
0.4852 0.2022 0
0.8913 0.5355 0.5397
1.0262 0.6738 0.6779

I a previous post on xlswrite, http://www.mathworks.com/matlabcentral/newsreader/view_thread/267281 a similar problem which wrongly placed decimal point is mentioned. But I don't know how to solve this. I also tried to convert to csv format first, but the same problem persists. How do I use num2str to solve this? Or can it be used?

Jan Simon

unread,
Jan 3, 2010, 7:40:05 AM1/3/10
to
Dear Marat!

> I tried xlsread('file.xls'). Below is what I get:
> 1.0e+003 *
>
> 0 0.3635 0.4852
> 0.3635 0 0.2022
> 0.4852 0.2022 0
> 0.8913 0.5355 0.5397
> 1.0262 0.6738 0.6779

I assume, this is not "what you get", but "what you see". Please try to set the format of the output in the Matlab window to full prcision:
format long g
Then display the array again.

Kind regards, Jan

David

unread,
Jun 15, 2012, 12:26:06 PM6/15/12
to
"Jan Simon" wrote in message <hhq375$jpe$1...@fred.mathworks.com>...
Jan,
Similar problem. Tried format long g, and sure enough it displays full precision of values read in, but when I pass the array values to another function they're back to 4 decimal places. How do I address this?

thanks!

-Dave-

Steven_Lord

unread,
Jun 15, 2012, 12:34:32 PM6/15/12
to


"David " <david.desroch...@jhuapl.edu> wrote in message
news:jrfnmu$b6q$1...@newscl01ah.mathworks.com...
I'm highly skeptical that passing the values to another function changes the
values stored; if they were read in as double precision numbers, and nothing
explicitly or implicitly converted them into another type (passing them into
another function would NOT convert them) then they better be double
precision. They're probably only being DISPLAYED with lower precision in
that function. For instance, if you're looking at them by hovering over the
variable name in the Editor, I believe those tooltips only show 4 decimal
places for readability. Or the function may use FPRINTF or SPRINTF with a
format specifier that only shows 4 decimals.

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Qian Ma

unread,
Feb 18, 2013, 11:54:06 AM2/18/13
to
"Marat Mamat" wrote in message <hhq09c$ibs$1...@fred.mathworks.com>...
REPLY FROM QIAN:

Hi, Marat,

I think I found a solution for your problem. Before writing the command "xlsread", you can first input "format long", and then do the "xlsread". This will import as many as 16 digits from your excel file.

When you check your imported variables in the Workspace, you will see that they are still shown in 4 digits. However, when you go to the command window and type the variable you would like to see and do not suppress the evaluation with a semicolon, you will see the variables in 16 digits.

Hope that this helps.

Best,
Qian

Steven_Lord

unread,
Feb 19, 2013, 10:12:34 AM2/19/13
to


"Qian Ma" <mqp...@live.cn> wrote in message
news:kftmbe$kgh$1...@newscl01ah.mathworks.com...
XLSREAD will read the data stored in your Excel file to full precision
(since I don't believe Excel has a 128-bit integer format or quad precision
floating-point or anything like that) regardless of the FORMAT setting. All
"format long" does is control how the data is _displayed_ in the Command
Window; it has no effect whatsoever on how the data is actually _stored._

Qian Ma

unread,
Feb 19, 2013, 10:17:15 PM2/19/13
to
"Steven_Lord" <slord@
mathworks.com> wrote in message <kg04p2$6gm$1...@newscl01ah.mathworks.com>...
Thank you Steve. You're right. Now I understand how it works.

Qian

Hamad

unread,
Mar 4, 2016, 10:20:11 AM3/4/16
to
try fix(xlsread('file.xls'))
or a=xlsread('file.xls'); b=fix(a)
0 new messages