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

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Compare a vector with a number

CB_10732001
2-Explorer

Compare a vector with a number

I have a vector of values and I would like to compare all these values inluced in the table in order to know if it is higher than 1. 

I was thinking to use "if" but I don't know how to use it. 

2 REPLIES 2
Werner_E
25-Diamond I
(To:CB_10732001)

Use A > 1 and you get a vector of 0's and 1's where a 1 (= TRUE) denotes an entry which is greater than 1.

Werner_E_0-1702920991985.png

If you insist that you want to see "OK" (and you have to provide a text/return value if the entry is smaller or equal to 1), you may define a function which expects a single scalar and returns those texts and call that function vectorized(!) with your vector A as argument.

Werner_E_1-1702921125673.png

I used the if-function when I defined the function "compare", but you may as well use the programmed if-statement instead

Werner_E_2-1702921207327.png

The reason we need to define a function is that Prime does not allow to vectorize the comparison operator, but it allows to vectorize the call of a function which uses that operator 😉

 

 

 

 

Hi,

Once you have the truth table of zeros and ones it is possible to trim out the zeros like this.

Capture.JPG

Announcements

Top Tags