cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Return only the KP value when F is greater than 0

davidlimtw
8-Gravel

Return only the KP value when F is greater than 0

Dear All,

 

I am trying to write a program to return the only KP values when F is greater than 0.

 

davidlimtw_1-1687172716513.png

 

 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:davidlimtw)

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

Werner_E_0-1687177203159.png

We can use a table built with augment to check the results

Werner_E_1-1687177248295.png

 

And here is a more "natural" approach with a function using a for loop

Werner_E_4-1687178081241.png

You can replace the 0m by NaN or whatever may be appropriate.

We can check if both ways return the same result

Werner_E_5-1687178123308.png

 

Using the if-function we can write it less space consuming

Werner_E_6-1687178181637.png

One may think that we could simply vectorize that if-function

Werner_E_8-1687178266989.png

but this does not work

Werner_E_9-1687178290269.png

because Prime does not allow to vectorize comparison operators like the < directly, but we are allowed to vectorize a function which uses the comparison:

Werner_E_10-1687178360095.png

Werner_E_11-1687178371793.png

 

Prime 9 worksheet attached

 

 

View solution in original post

3 REPLIES 3

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.

Werner_E
25-Diamond I
(To:davidlimtw)


@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

Werner_E_0-1687179913577.png

 

Werner_E
25-Diamond I
(To:davidlimtw)

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

Werner_E_0-1687177203159.png

We can use a table built with augment to check the results

Werner_E_1-1687177248295.png

 

And here is a more "natural" approach with a function using a for loop

Werner_E_4-1687178081241.png

You can replace the 0m by NaN or whatever may be appropriate.

We can check if both ways return the same result

Werner_E_5-1687178123308.png

 

Using the if-function we can write it less space consuming

Werner_E_6-1687178181637.png

One may think that we could simply vectorize that if-function

Werner_E_8-1687178266989.png

but this does not work

Werner_E_9-1687178290269.png

because Prime does not allow to vectorize comparison operators like the < directly, but we are allowed to vectorize a function which uses the comparison:

Werner_E_10-1687178360095.png

Werner_E_11-1687178371793.png

 

Prime 9 worksheet attached

 

 

Announcements

Top Tags