Borrar filtros
Borrar filtros

mean and peak for all sample

1 visualización (últimos 30 días)
Ishaq Alshuaili
Ishaq Alshuaili el 25 de Mayo de 2021
Comentada: Ishaq Alshuaili el 26 de Mayo de 2021
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?

Respuestas (1)

DGM
DGM el 25 de Mayo de 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)
A = 10×10
0.7105 0.3732 0.6008 0.1505 0.2378 0.3719 0.1127 0.7750 0.9504 0.2775 0.8302 0.0118 0.5578 0.2057 0.1885 0.2546 0.0788 0.2278 0.3845 0.1041 0.0135 0.0674 0.8598 0.5881 0.1280 0.9999 0.2626 0.7047 0.7745 0.5728 0.9912 0.8548 0.5598 0.7705 0.7054 0.4524 0.1961 0.8815 0.0596 0.1660 0.7031 0.8162 0.7211 0.1055 0.6576 0.5292 0.5518 0.2771 0.3455 0.3161 0.4669 0.1692 0.1344 0.3577 0.7394 0.5139 0.6424 0.9441 0.9933 0.8715 0.0840 0.1055 0.7442 0.2946 0.2792 0.2208 0.9380 0.9139 0.4512 0.9012 0.1633 0.1292 0.9782 0.6147 0.6756 0.3635 0.8992 0.0145 0.1988 0.8237 0.9181 0.7343 0.9633 0.9055 0.8752 0.3824 0.1803 0.3478 0.8031 0.7840 0.7233 0.6912 0.0834 0.4913 0.1718 0.1445 0.7990 0.9673 0.3888 0.5010
The mean is simple:
mn = mean(A(:))
mn = 0.5052
If you want the global maximum and the linear index:
[mx idx] = max(A(:))
mx = 0.9999
idx = 53
If you want subscripts instead of a linear index:
[suby subx] = ind2sub(size(A),idx)
suby = 3
subx = 6

Community Treasure Hunt

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

Start Hunting!

Translated by