LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Group 1d array elements by row

I am trying to create a VI that does the following: takes in a 1d string array that contains the group names.The goal is to create a 2d array that groups these strings based on a T/F condition, and it appends that values in the row where it belongs. I have attached a image showing an example input and its output. How do I do this?

 

Asasafuchi_1-1734699014825.png

 

 

0 Kudos
Message 1 of 10
(135 Views)

Hi Asa,

 


@Asasafuchi wrote:

The goal is to create a 2d array that groups these strings based on a T/F condition, and it appends that values in the row where it belongs.


You forgot to define this "T/F condition" and the term "where it belongs"!

 

How should we come up with suggestions when you even can't explain the goal in full detail?

 


@Asasafuchi wrote:

I have attached a image showing an example input and its output. How do I do this?


What have you tried so far?

Have you even sketched an algorithm using pseudocode?

Best regards,
GerdW


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

Yamaeda_0-1734700877768.png

 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 10
(120 Views)

Hi Gerd,

 

The input arrays will have the following structure that will determine the T/F conditions: 

Asasafuchi_0-1734703408709.png

The input array will have a text (in this case A,B,C etc) and then an interval (the brackets). IF the text matches AND the interval is within a certain distance or overlaps (determined by a subVI I created, then they are considered to be in the same group. I have tried initializing an array consisting of the first few unique elements, then using this to compare against the rest. If I find a match, I append it to the corresponding row, if not I add it to the row with largest index but I can't seem to get it right. I hope this was clarification enough.

0 Kudos
Message 4 of 10
(100 Views)

Hi Yamaeda, 

 

Thanks for the nice solution but maybe I was unclear in my description so I apologize for the confusion but if I have the following example array: 

Asasafuchi_0-1734703616946.png

where each group is one with the same text (in this case A,B or E) AND are within a certain distance or overlap in their intervals (as shown in the brackets). How can I modify the code you have provided to build the array? The check whether or not the intervals overlap or are within a certain distance I will do with a subV which returns a T/F value. True if they are within the same group, false otherwise.

0 Kudos
Message 5 of 10
(97 Views)

Here is the vi that does the interval check: 

0 Kudos
Message 6 of 10
(94 Views)

Can you share the other vi as well ? I don't need to know what your subvi is doing. But see what you did to better understand how can I help you . 

0 Kudos
Message 7 of 10
(59 Views)

@Asasafuchi wrote:

Hi Yamaeda, 

 

Thanks for the nice solution but maybe I was unclear in my description so I apologize for the confusion but if I have the following example array: 

Asasafuchi_0-1734703616946.png

where each group is one with the same text (in this case A,B or E) AND are within a certain distance or overlap in their intervals (as shown in the brackets). How can I modify the code you have provided to build the array? The check whether or not the intervals overlap or are within a certain distance I will do with a subV which returns a T/F value. True if they are within the same group, false otherwise.


 

This is still very unclear!

 

What is the "distance" here? Are you talking about the index of the element? Why are some of the ranges descending ( (e.g. [100-0]). What should the output be?

 

Can you attach a simple VI that contains small examples of typical inputs and the desired output? (all as default values!).

 

I am sure that can be solved with code the size of a postage stamp!

 

 

 

0 Kudos
Message 8 of 10
(50 Views)

@Asasafuchi wrote:

Here is the vi that does the interval check: 


Can you explain what the five inputs represent (cannot tell from the labels!) and how the boolean output should depend on them?

 

This is just pure Rube Goldberg code with convoluted constructs, way too much duplicate and unnecessary code.

 

Here's just the tip of the iceberg:

 

altenbach_0-1734713189611.png

 

0 Kudos
Message 9 of 10
(45 Views)

I think I got what you need. 

 

You probably have a main vi that receives the array with the brackets. then run your subvi that gives T or F. 

 

The Program needs to detect if the letter needs to be added as a new column (same group in your terminology) or be added as a new line.

 

The tricky part is how to update the 2D array properly. 

 

You need to carry one additional information that is the number of elements on each line. 

So the main VI will have a For loop with 2 shift registers, one for the 2D array string and anther 1D array that carries the number of elements. 

 

So for each new line you evaluate, you detect the Letter to evaluate the range (witch group it belongs to) then T /F and the sub that evaluates where this new letter should be added to , if it's a new column or a new line. Finally, it also detects how many elements the resulting 2D array will have  (with the number of elements that are not empty) that is going to be used on the next iteration

 

LVNinja_1-1734714408983.png

 

 

0 Kudos
Message 10 of 10
(35 Views)