Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Concatenating matrix columns causes loss of precision
Replies: 4   Last Post: Aug 24, 2013 12:03 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
James Tursa

Posts: 2,069
Registered: 8/5/09
Re: Concatenating matrix columns causes loss of precision
Posted: Aug 23, 2013 2:45 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Rohit" wrote in message <kv6sli$fml$1@newscl01ah.mathworks.com>...
> Hi all,
> I have a curious problem I'm hoping someone can help me with. I have a column matrix say temp1 with floating point numbers in the following format(displayed this way using format long g):
>
> 1334320224.86767
> 1334320225.03415
> 1334320225.20064
>
>
> and another nx3 matrix (temp2) with values like so:
>
> 25.59989 -17.82167 31.19241
> 25.17558 -17.59459 30.71448
> 25.18788 -17.39987 30.61347
>
> I concatenate the 2 matrices column wise, temp = [temp1 temp2];
> The resulting matrix is:
>
> 1.334305e+09 24.40084 -17.98591 30.31327
> 1.334305e+09 24.23554 -17.68831 30.00396
> 1.334305e+09 25.31328 -17.61529 30.83927
> I want the resulting matrix to have the original precision of temp1. How do I do this? I have already tried format long g. Writing to a file with dlmwrite and precision set to %.5f results in the fractional part zeroed out.


As long as the data types are the same, concatenation doesn't change the precision of anything. E.g., using your numbers:

>> format long
>> temp1 = [1334320224.86767;1334320225.03415;1334320225.20064]

temp1 =
1.0e+009 *
1.33432022486767
1.33432022503415
1.33432022520064
>> temp2 = [25.59989 -17.82167 31.19241;25.17558 -17.59459 30.71448;25.18788 -17.39987 30.61347]
temp2 =
25.59989000000000 -17.82167000000000 31.19241000000000
25.17558000000000 -17.59459000000000 30.71448000000000
25.18788000000000 -17.39987000000000 30.61347000000000
>> temp = [temp1 temp2]
temp =
1.0e+009 *
1.33432022486767 0.00000002559989 -0.00000001782167 0.00000003119241
1.33432022503415 0.00000002517558 -0.00000001759459 0.00000003071448
1.33432022520064 0.00000002518788 -0.00000001739987 0.00000003061347
>> isequal(temp1,temp(:,1))
ans =
1
>> isequal(temp2,temp(:,2:4))
ans =
1

Everything internally is the same. I suggest you review what you did and you will discover you did something else besides just concatenation of two variables of the same datatype.

James Tursa



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.