adding Fraction up as 1

4 visualizzazioni (ultimi 30 giorni)
Neesha
Neesha il 14 Ott 2014
Risposto: Image Analyst il 14 Ott 2014
Hi
I have data by location and i am trying to calc fraction. When i add up fraction back it does not aways sum up as 1. How do i ensure that it does. Example:
Say I have
187.631776923077
5462.0212
17.6735538461538
1044.35115384615
0
583.935553846154
0.983746153846154
sum of it is 7296.59698461538. And dividing each number above with 7296.59698461538 gives me
0.0257149705977584
0.748571040927226
0.0024221639050941
0.143128523618357
0
0.0800284783546852
0.000134822596879113
which sums up as 0.999865177403121.
When fractions are printed, i want such that it adds up as 1

Risposte (2)

Neesha
Neesha il 14 Ott 2014
I edited to add extra entry on each - original numbers and then related fraction

Image Analyst
Image Analyst il 14 Ott 2014
I don't see any problem:
m=[187.631776923077
5462.0212
17.6735538461538
1044.35115384615
0
583.935553846154
0.983746153846154
]
summ = sum(m)
m2 = m / summ
sum2 = sum(m2)
In command window:
m =
1.0e+03 *
0.1876
5.4620
0.0177
1.0444
0
0.5839
0.0010
summ =
7.2966e+03
m2 =
0.0257
0.7486
0.0024
0.1431
0
0.0800
0.0001
sum2 =
1

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by