10-20-2025 01:34 PM
Hello, I need help converting a 2D array that I receive from another application into the desired format for my application
The first array is how it comes from my application; I need to convert it to this second format that my application requires
Regarding the first table: the first column may vary between its values, it won’t always be Ph3 - Ph1 - Ph2
It can change among those options, and this first table may contain many more rows
10-20-2025 02:41 PM
Aren't you going to even try to solve this yourself? While it is helpful (and easier to read) to have the desired Input and Output arrays "visible" in the VI (but as a Control and an Indicator on the Front Panel, with the Indicator set (by hand, if necessary) to the "right answer", you need to think about how you would go about writing LabVIEW code to transform Input to Output.
If I were doing this, and had data (such as you show) "slightly scrambled", I might do it in several steps. First, I'd make sure that there were the same number of entries for each "Tap" row (n 1's, n 2's, etc.), and there were a corresponding number of "matched" Phase entries. Next, I might sort the Columns so Tap is the first, followed by R, then V, then I (note you don't need Phase at this point, since they are in 1, 2, 3, 1, 2, 3, ... order -- you just need to know "how many", or 3, in this case). So now you build the rows, column by column (you might not even need Tap, if it is always a numerical counter starting at 1).
This could be a wonderful way to present a problem that makes you think about how Arrays work in LabVIEW, and how LabVIEW gives you tools to build arrays either row-wise or column-wise. Sure, we could show you how we'd do it, but you would learn it much better (and faster) if you played with the Array functions themselves.
Bob Schor
10-20-2025 03:19 PM
I know that, I asked on the forum because I couldn't get to what I needed
I sent the "clean" code so I wouldn't have to delete anything when opening it
10-20-2025 03:44 PM - edited 10-20-2025 03:46 PM
While it is clear what you want, can we assume that the data is always clean as shown or can the input be more general?
10-20-2025 04:43 PM - edited 10-20-2025 04:46 PM
See if this can give you some ideas....
If the fields can differ in e.g. uppercase/lowercase or if there could be fields that don't match the three choices, more code is needed.
10-21-2025 06:16 AM
Are the rows always sorted by tap?
Not always, they may come in a different order, such as tap 3, 2, 1 or 1, 3, 2 or other variations
Are there always exactly three taps?
No, there may be only one tap or more; in this case, there were three
Are the Ph# always in the same order (3,1,2)?
No, it depends on what the operator selects at a certain step of the process
Is the output always the same size?
It should always maintain the same structure/number of columns. What changes is that if there is only one phase (for example: Ph2), only the columns referring to Phase 2 should be filled
10-21-2025 10:23 AM
My code does not require any specific sorting of the inputs as you probably noticed. If the input is incomplete, missing fields will just be left blank.
Earlier, you said:
@leandrofeder wrote:..., and this first table may contain many more rows
If the table has "many more rows" it is not clear how the output should look like. While my code draft can deal with properly formed inputs of many more rows, the output will overwrite earlier instances of the same output field. Is this what you want? Another option would be to average fields with multiple entries (not shown, but easy to do) or to create a comma delimited string of all entries.
10-22-2025 01:05 AM
You can easily extend the code of altenbach to unlimited TAPs.
Just scan the TAP number column for biggest number and initialize the output array with that number. If TAP does not start at 1, scan for MAX and MIN and subtract it from each other, so you get your targat array size. You can also easily replace the array constant {1;2;3} and the search function to find the insert index by directly converting the TAP to decimal number, decrementing and using this an input index for output array.