NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Data loss when resizing 2D array

Solved!
Go to solution

I'm collecting data and inserting into an array that I've made larger than I know will be used.  I then resize the array using SetArrayBounds because I now know the number of iterations that have been performed.  I end up with an array of the correct size but the data consists of the first row only with the first column missing.  All other elements are 0 (array of numbers).  Any idea what's going on?

 

I wanted to start with an empty array, resize to no rows and the known number of columns before starting the iterations, then add a row at the beginning of each iteration.  I was shot down on that but it seems like that would work better.

 

Kelly Bersch

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
0 Kudos
Message 1 of 6
(4,281 Views)

In most programming languages, multi-dimensional arrays are typically a flat block of memory where accessing dimensions is really an arithmatic calculation of an offset into the flat block of memory based on the indices, thus, even though the contents of the block of memory can be preserved on resize, which indices map to which element in the block could change depending on which dimension you resize. In TestStand, if you increase the size of the second dimension of a 2d array then the offsets of the previous indices remain unchanged, but if you increase the 1st dimensions then existing elements indices end up mapping to different offsets into the block.

 

If you provide more details about what you are trying to do and what sort of data is involved, I might be able to suggest a better alternative.

 

-Doug

0 Kudos
Message 2 of 6
(4,259 Views)

The idea is to output a 2D array of numbers to pass to a LabVIEW VI that writes the array to an Excel worksheet.  This test will step through input voltages and measure several input & output parameters.  We will know ahead of time how many parameters are being measured (columns) so those could be set before we start but we don't know how many iterations will be done because the target can change from teswt to test so we need to resize the array.  right now the array is set to 100x100 then resized after the test (not my idea).  if we dont resize all the data is there with a lot of extra cells.

 

I'd like to set the number of columns before the test starts and have the number of rows empty then resize the row dimension before each iteration.

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
0 Kudos
Message 3 of 6
(4,254 Views)
Solution
Accepted by topic author kbbersch

Hi Kelly,

 

Could you show us the code that you used to implement it? Specifically, the resizing of the array? http://forums.ni.com/t5/NI-TestStand/What-is-the-syntax-for-SetArrayBounds-for-a-multi-dimensional/t... That thread shows the correct syntax for the command and an implementation of it.

 

As I understand you are slowly filling this array which was initialized at 100x100. The first thing we should do is initialize the array at 100xthe number of columns so at least we can stop worrying about columns since you already know how many parameters you are testing. Then at the end of the sequence you can resize the rows by using the command above.

 

Regards,
Basil
Applications Engineering
National Instruments
0 Kudos
Message 4 of 6
(4,238 Views)

@kbbersch wrote:

The idea is to output a 2D array of numbers to pass to a LabVIEW VI that writes the array to an Excel worksheet.  This test will step through input voltages and measure several input & output parameters.  We will know ahead of time how many parameters are being measured (columns) so those could be set before we start but we don't know how many iterations will be done because the target can change from teswt to test so we need to resize the array.  right now the array is set to 100x100 then resized after the test (not my idea).  if we dont resize all the data is there with a lot of extra cells.

 

I'd like to set the number of columns before the test starts and have the number of rows empty then resize the row dimension before each iteration.


A couple of ideas:

 

1) If you treat the second index in teststand as your row then you can increase the size non-destructively. Start with an upper bound of [100][] and then change it to [100][0] then [100][1], etc.

2) Another idea is to use an array of arrays rather than a two dimensional array. Make your root level array be an array of Containers. In an array of containers, the elements can actually be any type, including arrays themselves. Insert a new element into the array that is an array itself as follows:

 

Locals.Array.SetPropertyObjectByOffset(GetNumElements(Locals.Array), PropOption_InsertElement, RunState.Engine.NewPropertyObject(PropValType_Number, True, "", 0)),
SetNumElements(Locals.Array[GetNumElements(Locals.Array) - 1], 100)

 

Such an array of arrays can be indexed similarly as a two dimensional array.

 

Hope this helps,

-Doug

Message 5 of 6
(4,228 Views)

It turns out I was correct in the way I wanted to do this.  I now start with my array diminsioned in one direction (columns).

 

SetArrayBounds(ArrayName,"[0][0]","[4][0]")

 

I then at the begining of each loop I resize.

 

SetArrayBounds(ArrayName,"[0][0]","[4]["+Locals.Count+"]")

 

It works well with no data loss.

 

Kelly Bersch

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
0 Kudos
Message 6 of 6
(4,051 Views)