LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Adding elements to an array

Solved!
Go to solution

Hello guys, i've been searching for a solution to my problem but i can't find the right answer..

 

Here is the thing ;


I have a variable (let's call it "Variable Case"). Every time this variable goes from 0 to 1, i want to add the value of another variable (let's call this one "Buse défectueuse") to an array of 2D. So far, nothing impressive, but things will get worse now !
To be sure that i correctly added the value of "Buse défectueuse" to my array, i've got another variable (let's call it "Correctly Added") that goes from 0 (nothing happened) to 1(the value has been added to the array). When "Correctly Added" is at "1", i must set the value of "Case" back from 1 to 0 (the variable "Case" is in a while loop that is refreshed every 100 ms so it's very important that "Case" goes to 0 as soon as the writting of "Buse défectueuse" is done) and once "Case" is back to 0, set "Correctly Added" to 0 aswell.
Also, the size of the array is set to 10 elements and each times that a value is written in it, i must increment the value of the index for the next value.

 


How it should be understood ;


First iteration :

  • i (of the array)=0
  • Case goes from 0 to 1
  • I insert the value of "Buse défectueuse" into the array
  • "Correctly Added" goes from 0 to 1 (the value has been written in the array)
  • I set back "Case" to 0
  • i (index of the array) ++
  • "Correctly Added" goes to "0"

Second iteration :

 

  • i (of the array)=1
  • Case goes from 0 to 1
  • I insert the value of "Buse défectueuse" into the array
  • "Correctly Added" goes from 0 to 1 (the value has been written in the array)
  • I set back "Case" to 0
  • i (index of the array) ++
  • "Correctly Added" goes to "0"

Third iteration (you got the thing...)

 

I've got everything working but the "i ++" thingy. Could you take a look at my vi and tell me what i've been doing wrong? Thanks for your help !

 

Download All
0 Kudos
Message 1 of 5
(3,810 Views)

Hi Claude,

 

in your VI you don't "add" or "insert" data to your array indicator, instead you create a new array (of only one element) each time.

 

Please go through all free LabVIEW courses to learn LabVIEW basics as autoindexing and shift register usage!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(3,795 Views)

If i post something here, that means that i couldn't find the right answer in the courses..

0 Kudos
Message 3 of 5
(3,778 Views)
Solution
Accepted by topic author Claude_David

Hello Claude,

 

what GerdW meant, is, that you didn't find the answers to a lot of questions.

  1. Because of the dataflow paradigm of LabVIEW, independent (i.e. not with wires connected) parts of the diagram run in parallel. So the sequence you described in your post will not execute in your VI, because the Case structure, the event structure and the select node are independent of each other. You can see this, if you run the VI in debugging mode, with the light bulb on.
  2. Shared variables are not the best way to store values, except you want to share these values with other applications, on remote machines. The best way to transmit values from one part of the Block Diagram to another is a wire!
  3. The "value change"- event only triggers, if the value is changed from the UI, that means from the user, or via property node's "value (signaling)". So in your VI this event will never trigger. And since the timeout terminal is not wired, the event structure will wait forever to execute and your loop doesn't cycle.
  4. The part with the select node is already described in the Rube-Goldberg-Thread, it means: If TRUE then TRUE else FALSE

 

I modified your VI, so it could meet to some of your needs. Take a look into it and perhaps you can answer the questions that came up to me:

 

  1. Why is "tableau initialisé" a 2D- array and at which index should the elements be inserted?
  2. Why is "tableau initialisé" limited to 5 rows and 2 columns and what happens, when you want to insert more elements? Do you start again with index 0? Does the while loop terminate?
  3. If you want unlimited size of "tableau initialisé", you need to use the "build array" node instead of "replace array subset".
  4. The time between setting "correctly added" setting to TRUE and resetting FALSE is very short (approximately 10 ns), do you really need this information?

 

 

 

For some reasons, I'm not able to post a VI. I get the error message, that the extension doesn' match the file type.

Greets, Dave
Message 4 of 5
(3,748 Views)

It might also mean the answers were in the courses, but you don't understand what the courses were teaching you.

 

Do you understand what a shift register is?  If you don't, retake the courses.  A shift register is what maintains the value in a wire and makes it available at the beginning of the next iteration of a loop.

 

PS.  You don't need the select statement with the True and False constants.  Just wire the boolean directly.  You have a Rube Goldberg.

0 Kudos
Message 5 of 5
(3,747 Views)