LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Insert into 2D array without moving previously indexed rows

Solved!
Go to solution

I have 4 identical functions I am collecting various forms of data from - Function1, Function2, Function3 & Function4. Part of my main VI collects one type of data for each function and stores it in separate 1D string arrays for each function. For example: [Function 1, 222]. Before I queue these arrays to send them to a separate loop I have for logging to file, I would like to collect them in a 2D array, queue this array and then parse this array in the logging loop. I would like the finalized 2D array to have the following format before it is sent:

 

[data1, ""

 Function1, 222

 Function2, 221

 Function3, 223

 Function4, 225]   

 

The order in which I collect the data from each function is random, so the issue I am having is in cases where for example, Function2's data is received before Function1's. Upon running the attached VI, my output array would look like this:

[data1, ""

 Function1, 222

 "" , ""

 Function2, 222]

 

This of course is caused by Function2 being inserted in row 3 initially, but an empty row is automatically indexed above it. Hence when Function1's data is added, it shoves the other two rows down. I was hoping that Function2 could keep its position so the array would look like:

[data1, ""

 Function1, 222

 Function2,222]

 

I looked into deleting empty rows before adding a new row of data, but in cases where Function1 is followed by Function3, for example, this wouldn't work. This appears to me like a really simple problem to solve (I just do not have enough experience), so without over complicating my VI with lots and lots of conditional blocks, I thought to look for some advice here. I would like the initial index of assigned to a row to remain in place as the array is being formed. I would also like to know how best to do this when inserting elements into a 1D array

 

It strikes me after attempting this that 2D arrays are not a good solution for something like this. I am looking for an addressable way of storing the data. Is there a much easier way of collecting this data that would make parsing it in the logging loop even more straight forward?

 

Thank you

Download All
0 Kudos
Message 1 of 4
(1,126 Views)
Solution
Accepted by topic author jcarr00

I'm a bit fuzzy on the intent. I think I understand it as you want this VI to update a particular row of data, and what row that is depends on which function the data belongs to?

 

If that's the case, I think what you want is not Insert Into Array, but Replace Subset. Then you can automatically dictate which row to replace based on which function the data belongs to. Inserting does just that, inserts, creating a new row. I think you just want 4 rows, so you want to Replace instead. Does that sound right? If so, definitely a simple fix!

 

I'd also note that you probably want to initialize an array of blank strings with the expected size (5 rows x 2 columns) at the beginning of the program. You can't replace a subset that doesn't exist yet.

0 Kudos
Message 2 of 4
(1,096 Views)

I think in some way, clusters are your answer here. Which way depends on a couple things:

 

If you're only queueing single bursts of data (four data points, one for each function) to your logging loop at a time, just a simple cluster would suffice as your queued data:

Spoiler
FireFist-Redhawk_0-1618845671515.png

If one batch of queued data could possibly consist of multiple data points from each function, something a bit more complex might suit you, I'd also ask whether your data is always 1:1:1:1, aka do all your functions give data at exactly the same rate:

Spoiler
FireFist-Redhawk_1-1618846278155.png

Sorry to give you so many options, but there's dozens of ways to group data and dozens of corresponding ways to parse it on the other end. Choose the easiest, most convenient one that you are comfortable using.

 

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

Message 3 of 4
(1,070 Views)

Thank you very much for the detailed answer. I accepted MrMattPayne's answer as the solution as it is the exact solution I was initially looking for. However, your description of how clusters could be applied show that this would be a better solution overall for how I am hoping to pack and unpack the data (each hardware function would have just a single data point for this format). Thanks for the help!

0 Kudos
Message 4 of 4
(1,058 Views)