function [ zq, xq ] = nanmeanquantized( x, y, z ) % (C) Demetrio Ferro demetrio.ferro@upf.edu % Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License % find avg z at index y with value x % try it with % xx=[0 1 2 3 4]; % 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]; % 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]; % xq=[.5 1.5 2.5 3.5] % zq=[NaN 4 5 6]; % or % xx=0:.1:1; % 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 ] % 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] % xq=[.05 .15 .25 .35 .45 .55 .65 .75 .85 .95] % zq=[ 1 2 3.4286 NaN 5 6 7 8 9 10] % or % xx=[0 .25 .5 .75 1]; % yy=[.1 .3 .8 .2 .85 .4 .65 .7 .5 .9]; % zz=[0 1 1 0 1 1 0 0 1 0]; % zq=[0 1 .3333 .6667]; % xq=[0.125 0.375 0.625 0.875]; xq=nan(1,length(x)-1); zq=nan(1,length(x)-1); for ix=1:(length(x)-1) xq(ix)=x(ix)/2+x(ix+1)/2; if ix==(length(x)-1) zq(ix)=nanmean(z(y>=x(ix) & y<=x(ix+1))); else zq(ix)=nanmean(z(y>=x(ix) & y