필터 지우기
필터 지우기

Sum of subsets /= sum of whole??

조회 수: 1 (최근 30일)
Sam
Sam 2014년 11월 14일
댓글: Sam 2014년 11월 14일
I have a MATfile (attached) containing a 3-dimensional array of size [90 144 120]. The array is called ba_lm3. If I subset the array into two equally-sized halves, the sum of all values in each of those halves is different from if I sum all values in the original array. Take a look:
>> sum(ba_lm3(:))
ans =
46601836
>> sum(sum(sum(ba_lm3(:,73:144,:)))) + sum(sum(sum(ba_lm3(:,1:72,:))))
ans =
46604364
The 2nd (subsetted) dimension of the sub-arrays is indeed 72+72=144:
>> size(ba_lm3(:,73:144,:))
ans =
90 72 120
>> size(ba_lm3(:,1:72,:))
ans =
90 72 120
>> size(ba_lm3)
ans =
90 144 120
And I don't think there should be any overlap.
I have observed this problem on machines running MATLAB r2009b and r2013b, so I think it must either be a problem with my code or the array. Any ideas?
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2014년 11월 14일
Your problem is not clear
James Tursa
James Tursa 2014년 11월 14일
What is the class of ba_lm3?

댓글을 달려면 로그인하십시오.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 11월 14일
편집: Azzi Abdelmalek 2014년 11월 14일
a_lm3 is a single array, if you want to get the same result
ba_lm3=double(ba_lm3);
a=ba_lm3(:,1:72,:);
b=ba_lm3(:,73:144,:);
s1=sum(ba_lm3(:))
s2=sum(a(:))+sum(b(:))
  댓글 수: 1
Sam
Sam 2014년 11월 14일
That's it! Thanks so much.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by