Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
Hello,
I have a vector:
And I want to make a short program in which to verify if each element in the vector is less or equal than 4.4A, or is greater than 4.4A.
And in case if an element is greater than 4.4A to set that element to 4.4A.
Solved! Go to Solution.
A generic function which provides a lower and an upper limit should do the job if you call it vectorized
A generic function which provides a lower and an upper limit should do the job if you call it vectorized
Nice, thanks!
@Cornel, if you want to keep the built in "min" function in your calculations, you only need to create a range the size of the array, then do a limit check:
The "min" and "max" functions do not like vectorization. I wish it did, or it being an option. As an Engineer (the thrust of PTC marketing), we deal more with 'data' than we do with complex math.
I use origin=1 since starting at zero is more of a 'coding' custom. You can use the built-in variable "ORIGIN" but I find it not as 'elegant' looking (ORIGIN being the reference to the first element in an array/matrix, either 1 or 0) . My preference and a cleaner way, imho, to define a nicer looking variable:
@SPaulis wrote:The "min" and "max" functions do not like vectorization. I wish it did, or it being an option. As an Engineer (the thrust of PTC marketing)
I do not understand this above your wrote...
Min and max function do not like vectorization but they actually seems to work fine with vectorization as @Werner_E solution shows. Then what could be the problem of why min and max functions do not like vectorization?
You cannot vectorise an expression with min or max directly, it doesn't work. But a function using min or max can be vectorised.
QED
Success!
Luc