LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Insert data into an array problem. Please Please I need your help guys!!!! I'm so frustrated.

Solved!
Go to solution

How do I insert an element into an array? I have tried all the possible solutions and nothing seems to work. For example, in the picture below I am trying to insert 148.651 only into the first row of the array, It keeps spreading in all the rows. So the goal is to have one number in the first, a different number in the second, another different in the 3rd and so on. But it just does not work for me. Take a look at the pictures below and you'll see what I mean. 

Note: The local variable in the block diagram is generating all kinds of numbers, not just 148.651 

 

 

 

.Capture.PNGCapture 1.PNG

0 Kudos
Message 1 of 14
(1,303 Views)

Your loop is done in a few nanoseconds and it is unlikely that the local variable changes during that. Please provide context for the overall problem you are trying to solve, maybe attach some code.

 

Also, to append elements to an array, "build array" is the correct function. No need to keep track of the index. Note that your blue wire is the same as [i]. It is unlikely that you need a local variable at all.

0 Kudos
Message 2 of 14
(1,298 Views)

I have attached the VI. The main one I need help with is called ONGOING TRY OUT. The reason I attached so many codes is because they are all related. They all need to be saved in the same file; otherwise, you will get a broken VI.

0 Kudos
Message 3 of 14
(1,287 Views)

Sorry, posting by phone. Will look at it later...

0 Kudos
Message 4 of 14
(1,277 Views)

No probelm. Thanks I appreciate it. I look forward to hearing from you.

0 Kudos
Message 5 of 14
(1,271 Views)

I don't think I understand what you are doing here but seriously this will do what you are asking..

 

numbarray.png

 

If you want to add an element to the "top" of an Array use Build Array

 

numarray2.png

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 6 of 14
(1,257 Views)

The resistance variable isn't going to be updated while the for loop is executing - it will always be the same value. It looks like the code calculates that resistance value, waits for 9 seconds, then writes it to the array. What do you want it to do? Even if the updating of that value was happening in parallel, you almost certainly wouldn't want to do it the way you have it written - you would have no control over what values actually get put into the array. If you want to get every value into that array, maintain the array in a shift register on your outer loop (or in the big cluster), then each time you calculate the value, add it to the array.

0 Kudos
Message 7 of 14
(1,251 Views)

I have tried this and I kept getting the same thing. 

0 Kudos
Message 8 of 14
(1,216 Views)

Your overall program architecture is flawed to say the least...

 

How do you expect the Resistance Local Variable to be updated 100 times in this state...

 

bs1Capture.PNG

 

When its terminal is in a different state of the same state machine?

 

Bs2Capture.PNG

 

The code in "Meas Coil R" state is NOT being ran when you are in the "Log values" state.

 

So the Resistance Local Variable is NOT updated, this is why "Log values" logs the exact same "Resistance" value 100 times.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 9 of 14
(1,210 Views)

What exactly have you tried? Do you fundamentally understand why as currently written the code would never work the way you want it to? (This is pretty key to understanding how to program in LabVIEW)

 

You are only computing one value of resistance. The for loop inserts that value into an array. If you want to insert many values, you need to compute the value, insert it into the array, then compute a new value, and insert or append the new value to the array, continuing this way each time you compute a new value.

 

0 Kudos
Message 10 of 14
(1,203 Views)