-1

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 of first column zeroed out.

  • There is this feeling that you are doing something wrong, I dont see matlab messing up with the values precision. Maybe the `dlmwrite` would not write the array to full precision, but I havent checked that. But your values changing due to concatenation is quite strange… – Werner Aug 23 '13 at 06:10
  • This works fine for me: `dlmwrite('FILENAME.txt',temp,'precision','%.5f','newline','pc')`. Please make sure your example illustrates the problem. (Perhaps try whether it occurs when column 1 is at its maximun and one of the others at its minimum?) – Dennis Jaheruddin Aug 23 '13 at 11:34
  • What you don't appreciate is this is NOT a loss of precision, but merely a change in the display. The numbers are still stored properly. –  Aug 23 '13 at 12:47

1 Answers1

1

First, format long g worked for me. I am using Matlab_R2013a on mac:

>> temp = [temp1 temp2]

temp =

          1334320224.86767                  25.59989                 -17.82167                  31.19241
          1334320225.03415                  25.17558                 -17.59459                  30.71448
          1334320225.20064                  25.18788                 -17.39987                  30.61347

But a simple solution: sprintf('%f ',temp), it will lose the matrix look-like formating, but you will be able to see as you want. The output:

>> sprintf('%f ',temp)

ans =

1334320224.867670 1334320225.034150 1334320225.200640 25.599890 25.175580 25.187880 -17.821670 -17.594590 -17.399870 31.192410 30.714480 30.613470 

If you reaaaally need to see as you pointed out you might want to do:

>> arrayfun(@(in) sprintf('%f',in),temp,'Uniform',0)

ans = 

    '1334320224.867670'    '25.599890'    '-17.821670'    '31.192410'
    '1334320225.034150'    '25.175580'    '-17.594590'    '30.714480'
    '1334320225.200640'    '25.187880'    '-17.399870'    '30.613470'
Werner
  • 2,537
  • 1
  • 26
  • 38
  • OK I should have mentioned it, but left it out thinking it made no difference: this is just 3 rows of a matrix of 518944 rows. Could it be some memory issue or something else to do with large matrices? – user1984537 Aug 23 '13 at 06:18
  • @user1984537 Yeah, it seems so. Maybe someone else can explain you what is happening, unfortunately I can't. But check if you can reduce the order from the outliers so that they fit to a reasonable range and check if your problem is over. Then all you will need to do is to map the outliers. If you know that only the first column for example will be from outliers from a specific order, just remove this order of magnitude and add it when necessary. Dont know if this is an applicable solution, but anyway… – Werner Aug 23 '13 at 06:26