# mean according to another column

3 views (last 30 days)
Thar on 16 Jan 2015
Commented: Thar on 16 Jan 2015
My data are in 4 columns:
5,11550634065452 5,68000000000000 2,89500000000000e+18 0,000277777777777821
5,11371667045788 5,68027777777778 4,28850000000000e+18 0,000277777777778709
5,11237469650691 5,68055555555556 3,99960000000000e+18 0,000277777777776933
5,11058681295688 5,68083333333333 3,56330000000000e+18 0,000277777777777821
4,22865065482816 5,89750000000000 2,74900000000000e+18 0,216666666666667
4,22683293766465 5,89805555555556 3,82680000000000e+18 0,000555555555555642
4,22531743417035 5,89861111111111 3,05860000000000e+18 0,000555555555555642
4,22380486438042 5,89916666666667 3,72440000000000e+18 0,000555555555555642
4,22229371155370 5,89944444444445 3,42520000000000e+18 0,277777777777821
4,22078125510264 5,90000000000000 2,90090000000000e+18 0,000555555555555642
4,21927232883456 5,90027777777778 2,72760000000000e+18 0,000277777777776933
4,21806586681390 5,90083333333333 3,59180000000000e+18 0,000555555555555642
4,21655652713407 5,90138888888889 4,65340000000000e+18 0,000555555555555642
I'd like to find mean values from columns 1:3, but not from all lines. The 4th column has some lines where the number is >0.01, like the lines 5 & 9. So, I want to find the mean from lines 1-4, 5-8, and 9 until the number from 4th column is >0.01 and so on, until line 4878. (the step is not stable).
What can i do?
Thank you!

Azzi Abdelmalek on 16 Jan 2015
If your matrix is named a
idx=a(:,4)<=0.01
out=mean(a(idx,1:3),2)

Thar on 16 Jan 2015
The result out has more lines from the first data. It not find mean values from lines 1:4 then 5:8 and so on. Can i do anything else?
Thank you!
Thar on 16 Jan 2015
my script is:
G=[X,X1,Y]; %airmass, time, SCD
for k=1:4828
G(k+1,4)=G(k+1,2)-G(k,2); %dif_time
end
idx=G(:,4)<=0.01;
out=mean(G(idx,1:3),2);