LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to insert 1d array into 2d array after for loop

Hello all,

 

I am trying to insert a 1d array into a 2d array. outside of 1 for loop. I can see the 1d array filling with values. However, when I probe the "Test_vals" 1D array outside of the inner for loop I can't see anything.

 

I thought this might be something dumb that I'm not understanding because the 1d array is a local variable "so possible the indicator is not available outside of the first for loop?" However, when I put the indicator outside the first inner for loop (between the first and second for loops), which maybe could mean to define it there instead, I still can't read that 1d array variable.

 

A picture of what I'm talking about and the attached vi is below. Any help greatly appreciated!

 

Thanks,

 

Rick

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

Hi Rick,

 

learn the LabVIEW basics!

Focus on "THINK DATAFLOW!" ("dataflow" is explained in the LabVIEW help!) and learn about using shift registers!

Also learn about the danger of local variables and their way into race conditions - like in your VI!

 

Solution: replace ALL local variables by wires and shift registers…

Best regards,
GerdW


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

Hi GerdW. Thanks for the suggestions!

 

I'm a little confused, I thought that I had the dataflow down correctly. My error line on the inner for loop has shift registers. I had thought that this erorr line would control the dataflow. So that by the time the error line was done with the inner for loop, the test_vals variable would be available outside of the inner for loop.

 

Can you please tell me the flaw in this thinking? I'm also unsure on how to read from an indicator without a local variable.

 

Thanks,

 

Rick

0 Kudos
Message 3 of 5
(1,750 Views)

@ricktrick26 wrote:

Can you please tell me the flaw in this thinking? I'm also unsure on how to read from an indicator without a local variable.

 


The data is in the wire, not in indicators! Indicators are to display information for the user, not to hold data for further use on the diagram.

 

  • None of your local variables are needed
  • Your outer FOR loop can never spin more than 2 times. Do you understand why?
  • Once you enforce proper dataflow using wires, your sequence structure is no longer needed.
  • Why is the index for the test_vals indicator set to 1921?
  • Why are most array controls/indicators set to show only one elements, but have the indices nonzero? resize for a reasonable view and show the scrollbars!
  • The lower left case structure only differs in one scalar value. the rest belongs outside the case structure
  • Here is one glaring race condition (picture) (and no, placing another sequence structure is NOT the correct solution!)
  • Why are there so many coercion dots???
  • Your error wired does not go into the shift register, but is wired on top of it.
  • Typically, "built array" is preferable to "insert into array" when appending.
  • Most of your logic makes no sense and is overly complicated.
  • It is significantly more memory efficient to append rows instead o columns. (appending columns requires significant rearrangement of most elements in memory). You can always transpose for display.
  • etc. etc. etc.

 

altenbach_1-1645988910466.png

 

 

 

Do you have a simplified caller VI that has typical data wired? Do you have a description what the VI should do? I get the feelings that that entire task required only half a postcard worth of code (or less!)

 

0 Kudos
Message 4 of 5
(1,726 Views)

To point you in the right direction, here's a simplified version how your for loop stack would deal with the orange 1D and 2D arrays.

 

(I assume you want to start over with the test_vals" array for each iteration of the outer loop. It does not make sense to append longer and longer rows to the 2D array, each containing all previous data.)

 

altenbach_0-1645992261738.png

 

0 Kudos
Message 5 of 5
(1,714 Views)