Issue with summing values within a row of a matrix

2 views (last 30 days)
Hello,
I've been using matlab to analyse so data that is in the form of a 30 column , many rowed matrix (loaded in via 'load' from a '.txt'file), and example of a row being:
1.00E+00 3.89E-03 1.69E-08 3.56E-04 4.66E-01 5.33E-01 4.44E-04 1.55E-10 4.49E-21 7.83E-36 1.62E-55 2.02E-79 5.9197-109 1.2858-142 9.8305-181 3.4559-234 7.2987-292 0.00E+00 0.00E+00 0.00E+00 0.00E+00 0.00E+00 0.00E+00 0.00E+00 0.00E+00 0.00E+00 0.00E+00 0.00E+00 0.00E+00 0.00E+00 0.00E+00 0.00E+00
However when I get some wierd results when using this and I think Ive foudn the source of the issue: This data is normalised so that all values in a row sum to 1 (feel free to check in excel or what have you), however when performing a sum of the columns (which is one of the tasks I need to do) such as: 2);
sum(a_data, 2);
I get the value of 17.1830 for the row quoted above... (where a_data is the matrix containing all the rows as shown above)
I have a feeling it is due to the nature of some of the smaller values, however from looking into the documentation, as long as a answer isn't associated to a variable name i.e.
x_data = sum(a_data, 2);
then summing any variable (whether it be double, floating point etc) should be ok?
Any advice on this and maybe a better way to handle such data would be appriciated. Thanks
  2 Comments
Thorsten
Thorsten on 3 Dec 2015
Edited: Thorsten on 3 Dec 2015
In your sample row, some values are given in scientific notation, like 2.02E-79, while others are given as a difference of two values, like 5.9197-109. Is this correct?
I got the result -9.282057099829449e+02 if I sum this row.
and sum(a_data,2) is a sum of the rows, not the columns as you write.
It would be helpful if you post your original data file.
David
David on 3 Dec 2015
Yes I feel this may be the answer (as someone else has pointed out)... this file seems to truncate out the 'E' in the standard form notation if the power is more than 3 sig figs.
Sadly I cannot post the file yet this does seem like the source of the error.
And yes thats my bad in terms of my grammar with respect to what i meant regards sum(x, 2) and rows/columns.
thank you!

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 3 Dec 2015
I spotted some values like
5.9197-109
which I am guessing were supposed to be
5.9197E-109
and I expect that is the source of your problem. Perhaps something went haywire with the data import.
  1 Comment
David
David on 3 Dec 2015
Yes that isnt what its meant to be at all! It turns out that the program that makes this file likes to truncate out the 'E' in the standard form if the power is 3 sig figs or more.
Completely missed that, thanks for pointing it out! Amazing what a fresh pair of eyes spot

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!