mean and peak for all sample
1 次查看(过去 30 天)
显示 更早的评论
this code for one sample :
[M,I] = max(pz3,[],2);
Msg=sprintf('peak is %f and it is locatedat %i index of the array\n ',z(I(1)),I(1));
disp(Msg);
M1 = sum(z.*pz3(1,:))/sum(pz3(1,:)) ;
Msg=sprintf('mean value is %f \n ',M1);
disp(Msg);
how I can generalize it to the entire sample?
0 个评论
回答(1 个)
DGM
2021-5-25
What is "the entire sample"? Is it the entirety of pz3? Is it each row? Is it z.*pz3?
I'm going to just assume that you want to find the max and mean of a 2D array called A.
A = rand(10)
The mean is simple:
mn = mean(A(:))
If you want the global maximum and the linear index:
[mx idx] = max(A(:))
If you want subscripts instead of a linear index:
[suby subx] = ind2sub(size(A),idx)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!