LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiplying element in array if the value is under a certain threshold

Solved!
Go to solution

Hey guys,

 

I've stumbled onto a small problem. I have an array that contains 500 elements with values between 1 and 10. What I want to do is find all the values below a certain threshold and multiply them with a constant.

So for example I want to find all the elements with a value lower than three and then multiply them by two, all the other elements that have a value higher than three stay the same as before. 

Is there a simple way of doing this?

 

Kind regards, 

Victor

0 Kudos
Message 1 of 16
(5,122 Views)

Use a for loop with auto-indexing enabled on the input array tunnel, do the comparison and multiplication, and then auto-index it back into an array. 

aputman
Message 2 of 16
(5,118 Views)

Yes.   A For Loop that auto-indexes on the array.  It either feeds the element through, or multiplies it by two.

0 Kudos
Message 3 of 16
(5,117 Views)
Solution
Accepted by topic author victorlarsson

Just because I need kudos today T and Scale.png

EDIT: I hope I beat GerdW


"Should be" isn't "Is" -Jay
Message 4 of 16
(5,088 Views)

loopless:

check.png

(loopless doesn't mean it's more efficient… :D)

 

Edit: Damn, Jeff was faster… 😄

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 16
(5,087 Views)

Implemented the way the problem was stated.

 

The other solutions look cool and may not use loops, but they use some unusual "hacks" to do that.  It may not be as clear to someone else reading the code as to what is going.

 

I'd prefer clarity.

 

 

 

Question to original poster.

 

You said values less than 3 get multiplied.  Values greater than 3 stay the same.

What do you want done when the value EQUALS 3?

Message 6 of 16
(5,032 Views)

i want kudos too 😉

 

array-mult-with-threshold.png


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 7 of 16
(5,020 Views)

@jwscs wrote:

i want kudos too 😉

 

array-mult-with-threshold.png


Sorry.  No kudoes.  A conditional tunnel determines whether a value is included in the output array or not.  You created code that only outputs an array of values that were multiplied discarding all the ones that weren't.

Message 8 of 16
(5,012 Views)

you got me 😉


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 9 of 16
(5,008 Views)

@RavensFan wrote:

 

The other solutions look cool and may not use loops, but they use some unusual "hacks" to do that.  It may not be as clear to someone else reading the code as to what is going.

 

 


 HACK? when did  "Elementary Arithmetic" operations become HACKS? 


"Should be" isn't "Is" -Jay
0 Kudos
Message 10 of 16
(5,003 Views)