adding Fraction up as 1
Show older comments
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
Answers (2)
Neesha
on 14 Oct 2014
0 votes
Image Analyst
on 14 Oct 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
Categories
Find more on Simulink 3D Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!