Dear All,
I am trying to write a program to return the only KP values when F is greater than 0.
Solved! Go to Solution.
Again its not really clear what exactly you expect as result and giving one or two examples would have helped.
In the following approach I assumed that you want a vector with the values of KP but replace the original value if the value in F at the corresponding position is negative.
Here is a short approach using vectorization
We can use a table built with augment to check the results
And here is a more "natural" approach with a function using a for loop
You can replace the 0m by NaN or whatever may be appropriate.
We can check if both ways return the same result
Using the if-function we can write it less space consuming
One may think that we could simply vectorize that if-function
but this does not work
because Prime does not allow to vectorize comparison operators like the < directly, but we are allowed to vectorize a function which uses the comparison:
Prime 9 worksheet attached
I would like to add also a function to filter to return only the KP where F > 0 and another matrix showing the only F > 0 values.
@davidlimtw wrote:
I would like to add also a function to filter to return only the KP where F > 0 and another matrix showing the only F > 0 values.
Examples always would be welcome to clarify what exactly is needed.
A I understood it now you want the values in both vectors removed when F is zero or negative so only the positive values in F remain and also the corresponding values in KP?
Could be done in many ways, one is shown here
Again its not really clear what exactly you expect as result and giving one or two examples would have helped.
In the following approach I assumed that you want a vector with the values of KP but replace the original value if the value in F at the corresponding position is negative.
Here is a short approach using vectorization
We can use a table built with augment to check the results
And here is a more "natural" approach with a function using a for loop
You can replace the 0m by NaN or whatever may be appropriate.
We can check if both ways return the same result
Using the if-function we can write it less space consuming
One may think that we could simply vectorize that if-function
but this does not work
because Prime does not allow to vectorize comparison operators like the < directly, but we are allowed to vectorize a function which uses the comparison:
Prime 9 worksheet attached