LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Strange array behavior

I have included an (edited) screenshot of my program, and a screenshot of the excel data file and the expanded front panel array.

 

As seen in [array building.jpg] my program builds 2 seperate arrays, each with 3 columns and 4 rows, and then populates the arrays (most of which has been cut out.  the replace array subset functions used for inserting data are shown, but where it gets the data has been removed to make it a much smaller picture).  The program then takes those arrays, does a bunch of math (some hard coded, some in the formula node) and then stores that data to a 1 column, 4 row array labled "AC/DC Diff," which is then decimated into its elements and stored to a data file.

 

The second attachment [AC_DC difference.jpg] shows a screenshot of the data file, and a screenshot of the expanded AC/DC diff display on the front panel.  Take a closer look and your will realize the strangeness.  For some reason it stores the data in an offset-duplicate fashion on the front panel.  In the data file, the data is perfectly fine, the correct numbers appear, but on the front panel it looks like it generates extra dimensions.

 

I would have either expected the front panel display to be a single column, 4 row matrix of only data in the current iteration of the for loop, or a 2-D matrix containing all of the data, but as you can see, only data from the last iteration is present, and its duplicated in a strange fashion.

 

 

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

Lars,

 

The only thing I see is that the index displays are set to increasing values so that different parts of the array are displayed.  And what you show is what would be expected if all the array indicators are wired to the same data.  Since you do not show the indicator terminals, I cannot tell what you are really trying to show.

 

It is generally preferable to use wires rather than local variables to transfer data.  Your sequence structure does nothing. Dataflow will produce the same result without it.

 

You array building could be done much more compactly with a for loop and some arrays.  It is likely that the for loop approach is more readable and more easily modified.

 

Lynn

 

Array builder.png

 

Message 2 of 5
(2,696 Views)

Thanks for your response, let me try to give you some more info:

 

For compacting the array building, I like the idea but its going to be tough for this program because the sub.vis I have that capture the data points are not all the same, so I cant just throw a single one into a for loop like you do with your random number generator. 

 

As for the index displays (I assume you mean the one next to the AC/DC Diff display on the front panel) the indicator for the data is wired to the results terminal of the formula node, and is not indexed through the main for loop.  What the program is supposed to do is run that big for loop once for each frequency test point, creating a new 3x4 array each time, fill it with data, do some math, and then send it to the next layer of the "AC/DC Diff" indicator, which should end up with a 1x4 array for each test frequency. 

 

The "write to spreadsheet" vi is inside the for loop, so it writes the data each iteration and not at the end, so all the correct data is there are some point, it just gets overwritten.

 

My guess is that its because I make the array each time that it clears the indicator.  Maybe if I make a 3D array in the beginning (outside of the for loop), wire the size of the 3rd dimension to the number of test points, and then wire the main for loop iteration to the new 3rd dimension coordinate of my "replace array subset" vis.  That should put each 3x4 data set into the correct dimension.

0 Kudos
Message 3 of 5
(2,650 Views)

Lars,

 

For the array building you could take the individual data points from the various sources and build an array just as I did for the indexes.

 

I do not follow exactly what you mean by the rest of your comments.  It would help if we could see all of your program.  LV is a graphical language and trying to describe it in detail in words often comes up short of conveying real meaning.

 

Lynn

0 Kudos
Message 4 of 5
(2,639 Views)

I don't really understand what you mean. As you mention correctly the "AC/DC Diff" array is inside the for loop. It's a 1D array (1x4). It will update the values after each iteration of the for loop, but if you look at it after executing the VI you'll only see the values from the last iteration.

To see the values from all iterations you have to auto-index the 1D-array at the for loop border so you'll get a 2D array outside the loop.

Message 5 of 5
(2,634 Views)