Issue with summing values within a row of a matrix

1 回表示 (過去 30 日間)
David
David 2015 年 12 月 3 日
コメント済み: David 2015 年 12 月 3 日
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 件のコメント
Thorsten
Thorsten 2015 年 12 月 3 日
編集済み: Thorsten 2015 年 12 月 3 日
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 2015 年 12 月 3 日
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!

サインインしてコメントする。

採用された回答

the cyclist
the cyclist 2015 年 12 月 3 日
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 件のコメント
David
David 2015 年 12 月 3 日
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by