LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

incrementing each element of array

Solved!
Go to solution

I looked for this topic, but nothing stood out as to guide me in solving this. I have an array in which I want to increment each element by 2. 

On top I started with the basic concept to see it functioning.  I placed this in a for loop. It seems to be working when running but the values change back to what they were originally after each iteration. It seems the only element that changes it the last iteration of the loop. Basically I want  

 

Array Input    = {0,1,2,3,4}

Array Output = {2,3,4,5,6}

 

This seems like a basic concept but, I cannot get this.  Any help would be great thanks!

0 Kudos
Message 1 of 8
(3,315 Views)
Solution
Accepted by topic author Montn

Read the detailed help for each node and you will find all the functions in the numeric palette can accept an array as in input. Dispense with the FOR loop and wire the array right to the node you are using.  (I can't tell what it is - I don't have LV 2019 on this PC.)

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 8
(3,312 Views)

Thanks.    I attached a snapshot now  .   I notice in the file I sent I placed the input in the loop 

placed outside produces the same reslut.  

 

 

0 Kudos
Message 3 of 8
(3,309 Views)
Message 4 of 8
(3,296 Views)

As Bill was stating, you don't need a loop at all because the Add function will accept an array and a scaler.  It will add the scaler to all elements of the array.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 8
(3,289 Views)

Wow.   I thought I tried that but aparently not.   So I was just overthinking things . 

Thanks so much everyone.   !!

0 Kudos
Message 6 of 8
(3,276 Views)

@Montn wrote:

Wow.   I thought I tried that but aparently not.   So I was just overthinking things . 

Thanks so much everyone.   !!


That's why it's always better to have more than one pair of eyes look at an issue.  🙂

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 8
(3,254 Views)

While your algorithm problem has been solved easily, you really need to learn basic operations. Your code shows complete lack of understanding of loops and array operations. LabVIEW is much easier than you seem to think, so if you can describe the operation in one sentence, the code should not be larger than a postage stamp. If it fills the screen, be very suspicious! 😉

 

Your next problem might not be solvable by polymorphism alone, so here are some comments:

 

 

RGLoop.png

 

  • Having the array input terminal inside the loop is very dangerous, especially since you have a long wait. It means that the array value can be changed by the user (or from elsewhere via locals!) at random times, completely invalidating the result, whatever that might be. It also prevents many compiler optimization because the array source can no longer be considered as constant for the duration of the loop. The input array terminal belongs before the loop. 
  • Wiring a constant to N is dangerous, because N needs to depend on the array size.
  • Your are incrementing a blue integer in a shift register with each iteration. The same value can be obtained by wiring to the iteration terminal. None of your blue stuff is needed.
  • Indexing into an array with the iteration number is identical to autoindexing at the loop boundary. Now the loop will stop when it runs out of elements and you don't even need to wire N.
  • As you noticed, you are replacing from the same input array with each iteration, undoing all changes form previous iterations. To update all values, you need to keep the array in a shift register.
  • There is an "in place element function" that allows indexing and replacing in one step.

 

I recommend going back to the basic tutorials. Good luck!

0 Kudos
Message 8 of 8
(3,211 Views)