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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Translate the entire conversation x

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

Cornel
19-Tanzanite

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

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

 

ACCEPTED SOLUTION

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

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

 

View solution in original post

5 REPLIES 5
Werner_E
25-Diamond I
(To:Cornel)

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

 

Cornel
19-Tanzanite
(To:Werner_E)

Nice, thanks!

SPaulis
14-Alexandrite
(To:Cornel)

@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

 

 

 

 

Shawn P.
“It’s OK to fall in love with your heart. But, when it comes to making engineering decisions, don’t design with your heart.” – Blodgett, Omer W.
Cornel
19-Tanzanite
(To:SPaulis)


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

LucMeekes
23-Emerald IV
(To:Cornel)

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

Announcements

Top Tags