Calculating GeoMean of a double array

6 次查看(过去 30 天)
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
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
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!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Scan Parameter Ranges 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by