필터 지우기
필터 지우기

adding Fraction up as 1

조회 수: 3 (최근 30일)
Neesha
Neesha 2014년 10월 14일
답변: Image Analyst 2014년 10월 14일
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

답변 (2개)

Neesha
Neesha 2014년 10월 14일
I edited to add extra entry on each - original numbers and then related fraction

Image Analyst
Image Analyst 2014년 10월 14일
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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by