Prev: how to judge if an arc of a great circle crosses a quadrangle and calculate the positions of the intersects of on a sphere surface
Next: dataset help
From: Bayo on 12 Mar 2010 19:17 Hi Does anyone know if there's a function in matlab that compares the sign of two values? i.e it checks if they are both negative or positive? Bayo
From: John D'Errico on 12 Mar 2010 19:27 "Bayo " <ayb503(a)bham.ac.uk> wrote in message <hnelim$36s$1(a)fred.mathworks.com>... > Hi > Does anyone know if there's a function in matlab that compares the sign of two values? i.e it checks if they are both negative or positive? > No. There is no such explicit function. However, suppose you take the product of the two numbers? What happens if both of them are positive? What if they are both negative? John
From: Walter Roberson on 12 Mar 2010 19:27 Bayo wrote: > Does anyone know if there's a function in matlab that compares the sign > of two values? i.e it checks if they are both negative or positive? x and y have the same sign if sign(x)*sign(y) > 0 This has been constructed to return false if either or both numbers are 0, on the grounds that 0 has no sign. If you wish two 0's to be considered to have the same sign, then use sign(x) == sign(y) If you wish to consider two numbers to have the same sign if either of them is 0 or they both have the same sign (that is, that 0 is considered to belong to both sides), then use sign(x) * sign(y) > -1
From: Nathan on 12 Mar 2010 19:41
On Mar 12, 4:17 pm, "Bayo " <ayb...(a)bham.ac.uk> wrote: > Hi > Does anyone know if there's a function in matlab that compares the sign of two values? i.e it checks if they are both negative or positive? > > Bayo You can easily create one with outputs depending on what you are looking for: function pol = polfunc(a,b) %POLFUNC determines the polarity of two numbers % Inputs: two numbers, a and b % pol returns 0 if number have opposite signs % pol returns 1 if numbers are both negative % pol returns 2 if numbers are both positive signbool = a>0; if (a*b)>0 pol = signbool+1 else pol = 0; end end -Nathan |