Skip to main content
19-Tanzanite
April 11, 2025
Solved

How to verify each element in a vector if its greater than a certain value, and if so to change?

  • April 11, 2025
  • 2 replies
  • 1136 views

Hello,

I have a vector: 

Cornel_0-1744363178737.png

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.

Cornel_1-1744363347163.png

 

Best answer by Werner_E

A generic function which provides a lower and an upper limit should do the job if you call it vectorized

Werner_E_0-1744364595676.png

 

2 replies

Werner_E25-Diamond IAnswer
25-Diamond I
April 11, 2025

A generic function which provides a lower and an upper limit should do the job if you call it vectorized

Werner_E_0-1744364595676.png

 

Cornel19-TanzaniteAuthor
19-Tanzanite
April 11, 2025

Nice, thanks!

14-Alexandrite
April 11, 2025

@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:

SPaulis_0-1744381204391.png

 

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_1-1744381639532.png

 

 

 

 

Cornel19-TanzaniteAuthor
19-Tanzanite
April 11, 2025

@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?

23-Emerald IV
April 11, 2025

You cannot vectorise an expression with min or max directly, it doesn't work. But a function using min or max can be vectorised.

LucMeekes_0-1744393344204.png

QED

 

Success!
Luc