# Calculating GeoMean of a double array

조회 수: 4(최근 30일)
iceskating911 2022년 7월 1일
댓글: iceskating911 2022년 7월 1일
Hi! I'm still learning MATLAB and have a question about calculating the geometric mean.
Right now, I have a long forloop that is looping for 10 iterations. I have a 1x16 double array that is the result of the first part of my forloop and looks something like this: It is a 1x16 double array with a summed value in each array spot.
Now I want to take the geometric mean of each column in the same forloop to get another 1x16 double array with one value in each column.
So far, the part for that, looks like this:
a = SimData(:,78);
b = SimData(:,80);
for ii = 1 : length(edges)-1
indexes = a > edges(ii) & a <= edges(ii+1);
binByBinSums(ii) = sum(b(indexes)); %Summed value that creates the 1x16 double
boot_mean(i)=geomean(binByBinSums); %Geometric mean for each ieration of binByBinSums
end
However currently this code gives me boot_mean as taking the geometric mean across the board, 10 times, as shown below: How do I go about calculating the geometric mean of one column in a double? Any help is very appreciated, thank you!

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

### 채택된 답변

GeeTwo 2022년 7월 1일
% Here's some data for a sample
A=magic(4)
A = 4×4
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
% And here we'll calculate the geometric mean of each column
vect=prod(A,1).^(1/size(A,1))
vect = 1×4
7.3257 6.8142 7.2084 5.9437
##### 댓글 수: 1표시숨기기 없음
iceskating911 2022년 7월 1일
Ah! Makes perfect sense, wasn't sure if i was using the function geomean right in this way so thank you so much!

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

### 범주

Find more on Descriptive Statistics 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!