Issue with summing values within a row of a matrix

1 visualización (últimos 30 días)
David
David el 3 de Dic. de 2015
Comentada: David el 3 de Dic. de 2015
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 comentarios
Thorsten
Thorsten el 3 de Dic. de 2015
Editada: Thorsten el 3 de Dic. de 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 el 3 de Dic. de 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!

Iniciar sesión para comentar.

Respuesta aceptada

the cyclist
the cyclist el 3 de Dic. de 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 comentario
David
David el 3 de Dic. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by