functionz=copysignx(x,y)%COPYSIGNX Copy the sign%% COPYSIGNX(x,y) returns the magnitude of x with the sign of y. x and y% can be any compatible shapes.persistentoctavepifisempty(octavep)octavep=exist('OCTAVE_VERSION','builtin')~=0;endifoctavepz=abs(x).*(1-2*signbit(y));elsez=abs(x+0*y);l=z>-1&(y<0|(y==0&1./y<0));z(l)=-z(l);endend