LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I can't append array Inside Loop

Solved!
Go to solution

Hello,

 

I have a poblem where I want to use a cursor to place 2 point on a graph and then save the x and y data of those 2 cursors repeatedly until stoped. Which means that every single time I would like to save 4 data into an array, and move the cursors until satisfied and then save them again. I have tried using a while llop because the number of saves are not known prior. It is not working and I dont know why, I am bad at using shift registers and I think that is the problem, if you could help I would appreciate.

 

Screenshot 2022-06-03 151632.png

Cheers,

Diural

Download All
0 Kudos
Message 1 of 6
(1,413 Views)
Solution
Accepted by topic author Diural
  • Don't stack loops inside loops. Create a simple state machine.
  • You need a shift register if you want to build an ever-growing array. (see bottom image here)
  • Property nodes can be resized for multiple items.
  • Your loop needs some timing. You don't want millions of cursor positions per second even if nothing moves.
  • Use "cursor move" events.
  • You need to ensure that the file is read before the loop starts.(Currently both things happen in parallel)
  • Use the learning resources listed at the top of the forum

(Sorry, I cannot open your VI. consider "save for previous")

0 Kudos
Message 2 of 6
(1,394 Views)
Solution
Accepted by topic author Diural

You've got race conditions: Time time and order in which the Active cursor is being set is unpredictable.

Do this:

paul_cardinale_0-1654263650863.png

Also, the loop in a loop makes no sense.

 

"If you weren't supposed to push it, it wouldn't be a button."
Message 3 of 6
(1,390 Views)

Or:

 

altenbach_0-1654264290943.png

 

 

There is really no reason to create a 2D array with one row. You need to built array if you want to append a row to a 2D array in a shift register.

 

 

Message 4 of 6
(1,379 Views)

@Diural wrote:

I have a poblem where I want to use a cursor to place 2 point on a graph and then save the x and y data of those 2 cursors repeatedly until stoped. Which means that every single time I would like to save 4 data into an array, and move the cursors until satisfied and then save them again. I have tried using a while llop because the number of saves are not known prior. It is not working and I dont know why, I am bad at using shift registers and I think that is the problem, if you could help I would appreciate.

 


OK, let's throw away your code and start over:

 

  • First you need to define the problem and your terms.
  • What is "repeatedly"? As fast as the computer allows creating GB of data? Whenever the cursor has been moved by the user? At regular time intervals? I would recommend a "cursor move" event.
  • What is "until stoped"? You have two buttons named stop. Please use useful labels! Even of you stop the inner loop, the outer loop will immediately call the inner loop again. If you press the outer stop button, nothing will happen until the inner loop is stopped once more. Dataflow!
  • Maybe you could open the file before the loop and append data to the file whenever the cursor move event triggers. Now you don't even need a 2D array filling up your memory.
  • ....
0 Kudos
Message 5 of 6
(1,370 Views)

Altenbach and Paul,

 

Thank you very much for answering, I have changed and solved it thanks to you, and my code looks tidier now. Thanks a bunch, cheers !

 

Diural

0 Kudos
Message 6 of 6
(1,265 Views)