function indices=where(conditional) % where(condition) % % Returns the array indices corresponding to the array locations where % a specified condition is true. This function only works on vectors, % not arrays % % For example: % % ndex=(where(bob>0.02)) % % Will be all values of bob that are greater than 0.02 % % Originally written by Paul Ries Summer 2008 n=length(conditional); n_valid=0; returner=zeros(size(conditional)); for i=1:n if conditional(i) n_valid=n_valid+1; returner(n_valid)=i; end end indices=returner(1:n_valid);