Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
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?
V/r,
Devin
Solved! Go to Solution.
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.
So you must resort to other options.
One way uses vector indices to singly apply the if-function to each value
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.
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
A more generic approach is
which would deal with angles lower than -360° as well.
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.
So you must resort to other options.
One way uses vector indices to singly apply the if-function to each value
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.
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
A more generic approach is
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
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:
In your case also
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
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.
