nanmeanquantized.m 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. function [ zq, xq ] = nanmeanquantized( x, y, z )
  2. % (C) Demetrio Ferro demetrio.ferro@upf.edu
  3. % Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License
  4. % find avg z at index y with value x
  5. % try it with
  6. % xx=[0 1 2 3 4];
  7. % yy=[ 1 2 3 3 2 1 2 3 1 2 2 2 2 3 1 2 2 1 1 1 2 3 1 3];
  8. % zz=[ 4 5 6 6 5 4 5 6 4 5 5 5 5 6 4 5 5 4 4 4 5 6 4 6];
  9. % xq=[.5 1.5 2.5 3.5]
  10. % zq=[NaN 4 5 6];
  11. % or
  12. % xx=0:.1:1;
  13. % yy=[ 0 0 0 0 .1 .1 .1 .1 .2 .2 .2 .2 .3 .3 .3 .4 .4 .4 .5 .5 .6 .6 .6 .6 .6 .7 .7 .7 .8 .8 .8 .9 .9 .9 .9 1 1 1 1 ]
  14. % zz=[ 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 5 5 5 6 6 7 7 7 7 7 8 8 8 9 9 9 10 10 10 10 11 11 11 11]
  15. % xq=[.05 .15 .25 .35 .45 .55 .65 .75 .85 .95]
  16. % zq=[ 1 2 3.4286 NaN 5 6 7 8 9 10]
  17. % or
  18. % xx=[0 .25 .5 .75 1];
  19. % yy=[.1 .3 .8 .2 .85 .4 .65 .7 .5 .9];
  20. % zz=[0 1 1 0 1 1 0 0 1 0];
  21. % zq=[0 1 .3333 .6667];
  22. % xq=[0.125 0.375 0.625 0.875];
  23. xq=nan(1,length(x)-1);
  24. zq=nan(1,length(x)-1);
  25. for ix=1:(length(x)-1)
  26. xq(ix)=x(ix)/2+x(ix+1)/2;
  27. if ix==(length(x)-1)
  28. zq(ix)=nanmean(z(y>=x(ix) & y<=x(ix+1)));
  29. else
  30. zq(ix)=nanmean(z(y>=x(ix) & y<x(ix+1)));
  31. end
  32. end
  33. end