function B=threshsea(A,threshold) % A must be real and not complex! minvalue=min(min(A)); % find minimum value maxvalue=max(max(A)); % find max value sealevel=(maxvalue-minvalue)*threshold+minvalue; % 0 < threshold < 1 C=A-sealevel; % shift value down by sealevel maxCvalue=max(max(abs(C))); % find max value constant=1; if maxCvalue>0 % avoid divide by 0 C=0.9*(C/maxCvalue);% scale down between -0.9 and 0.9 constant=maxCvalue/0.9; end D=ceil(C); %form indicator of non-sea locations B=(D.*C)*constant; % scale from +/- 1 to 0,1