mean and peak for all sample
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
DGM
on 25 May 2021
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)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!