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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Translate the entire conversation x

Entering and Retrieving a Vector from an IF Statement

Devin_2020
8-Gravel

Entering and Retrieving a Vector from an IF Statement

Hello, I am trying to use an IF Statement to check one vector against another.  I would like to return the same value into a vector or an altered value depending on if the one vector's value at a row is above 0 degrees.  I have tried replacing Theta_0 with the value of 0 deg.  Either way I am getting an error that says the value must be a scalar.  Could someone help me figure out how to make this IF Statement function properly?

 

Devin_2020_0-1769593571351.png

 

 

V/r,

Devin

ACCEPTED SOLUTION

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

Normally, when you intend to feed a vector into a function written for scalars you would use vectorization. But unfortunately comparison operators like "<" can't be vectorized in Prime.

Werner_E_0-1769598962630.png

So you must resort to other options.

One way uses vector indices to singly apply the if-function to each value

Werner_E_1-1769599040697.png

 

Another option uses a utility function and call it vectorized. While the comparison operation can't be vectorized directly, a function using the comparison operator can be called vectorized.

Werner_E_2-1769599189249.png

 

As in your case the goal is just to normalize the angles to be in [0, 360°) you could do without theta0 and use the mod function 

Werner_E_3-1769599282963.png

 

A more generic approach is

Werner_E_5-1769599451338.png

which would deal with angles lower than -360° as well.

 

View solution in original post

3 REPLIES 3
Werner_E
25-Diamond I
(To:Devin_2020)

Normally, when you intend to feed a vector into a function written for scalars you would use vectorization. But unfortunately comparison operators like "<" can't be vectorized in Prime.

Werner_E_0-1769598962630.png

So you must resort to other options.

One way uses vector indices to singly apply the if-function to each value

Werner_E_1-1769599040697.png

 

Another option uses a utility function and call it vectorized. While the comparison operation can't be vectorized directly, a function using the comparison operator can be called vectorized.

Werner_E_2-1769599189249.png

 

As in your case the goal is just to normalize the angles to be in [0, 360°) you could do without theta0 and use the mod function 

Werner_E_3-1769599282963.png

 

A more generic approach is

Werner_E_5-1769599451338.png

which would deal with angles lower than -360° as well.

 

Werner,

 

Thank you very much!!  I will use your first example of theta_11_1.   I appreciate you responding so quickly too!

 

Sincerely,

Devin

Werner_E
25-Diamond I
(To:Devin_2020)

You are welcome.

I forgot to mention that if you. like me, don't want you worksheet to be cluttered with range variables which are only used once, you may replace it by a programmed for-loop:

Werner_E_0-1769600530492.png

 

In your case also

Werner_E_1-1769600631673.png

would work OK but the method would fail for angles larger than 90° or angles in the range from (-90°,0)

 

I guess I personally would rather prefer the last method in my previous sheet.

You may define a utility function "normalize" at the top of the sheet, maybe in a collapsed area) and use it later that way

Werner_E_3-1769601236175.png

I consider it good style to use vectorization here in case a vector argument is used instead of a scalar, but in case of this function it would not even be necessary to vectorize.

Announcements

Top Tags