I have created a vector that has both positive and negative values.
I would like to sum all the positive values, return the number, and then separately sum the negative numbers and return the number.
Is this possible?
Thanks,
Ross
Solved! Go to Solution.
Preferrably you should attach your Prime worksheet AND state which version of Prime you are using.
Apart from that, how about this...
Attached is a Prime 4 file, with the advice from @Werner_E (see below).
Success!
Luc
Preferrably you should attach your Prime worksheet AND state which version of Prime you are using.
Apart from that, how about this...
Attached is a Prime 4 file, with the advice from @Werner_E (see below).
Success!
Luc
You don't even need the summation operator
Hmm...
gives:
I think I prefer to have it in.
Or...
Now it works:
Luc
You are correct that vectorization is not mandatory here, because the comparison v>0 is not a valid operation for vectors and so Prime automatically switches to implicit vectorization.
But I learned (sometimes by hard) that its better to explicitly use vectorization when you want it to be done and don't rely on implicit vectorization. So I got used doing so.
BTW, if you'd like to extend to also be able to deal with non-real numbers (they should be ignored as they are neither positive nor negative), it looks like we a forced to use explicit vectorization because for reasons unknown to me, logical operators like AND (^) will not be implicitly vectorized:
@Werner_E wrote:
You are correct that vectorization is not mandatory here, because the comparison v>0 is not a valid operation for vectors and so Prime automatically switches to implicit vectorization.
But I learned (sometimes by hard) that its better to explicitly use vectorization when you want it to be done and don't rely on implicit vectorization. So I got used doing so.
BTW, if you'd like to extend to also be able to deal with non-real numbers (they should be ignored as they are neither positive nor negative), it looks like we a forced to use explicit vectorization because for reasons unknown to me, logical operators like AND (^) will not be implicitly vectorized:
To vectorize or not to vectorize?
Thanks appreciate the prompt response!