LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Group 1d array elements by row


@Asasafuchi wrote:

Thanks! This seems to work and is definitely more clear than my code. However I do have a follow up question: If instead my input was a 2D array with the following format: 


This is not clear at all, because in the original problem we create multiple columns from one row. If the input has multiple columns, but each row only occupies one of the columns, how exactly should groups be arranged. It seems unusual if both conditions can be fulfilled.

 

Can you give an example with more input fields?

 

In any case, you could just add an additional item that indicates the original column to the intermediary cluster and use that to place the elements at the very end into a 2D array of the correct size. Should be quite a trivial change to my code.

0 Kudos
Message 21 of 36
(308 Views)

Asasafuchi_0-1735585921666.png

So the objective is the same: append elements of the same type (same letter and interval requirement fulfilled) but the difference is that the input will be a 2d array instead of a 1d array. The grouping logic should be as follows: if an element belongs to the same group as another it should be appended to the row of the first occurence of this group type, for example: A[0-10] and A[20-40] are the same, A[20-40] gets appended to the row of A[0-10] because A[0-10] comes first and it gets appended to the second column because that was its original place. The input array will be structured such that each column only contains unique elements, so grouping them would mean only moving the row index of one element to another (notice how column 1 only contains elements of different groups).

0 Kudos
Message 22 of 36
(288 Views)

So did you try my idea?

 

If you want help, make my life easier and attach a simple VI containing the new inputs and desired outputs as default values. (No code, except for the terminals).

It is a waste of my time trying to read text from a screenshot and there are possibilities for typos!

0 Kudos
Message 23 of 36
(284 Views)

Yes, I tried your idea by adding a new 1d array containing each elements original column index but I couldnt successfully implement it. At any rate, here is an example VI containing the new inputs and outputs with default values. Sorry for the confusion.

0 Kudos
Message 24 of 36
(261 Views)

It seems you changed the format, because now there is no space after the first letter. How much variation do you expect in the formatting?

It still does not make sense to have a distance that is orange. It is an integer.

 

0 Kudos
Message 25 of 36
(249 Views)

You are right, there should be a space between the letters and the brackets. This was just an oversight on my part, no variation in the input will exist so hardcoding the scan from string like you did will still work. I have attached the same vi but with spaces added.

0 Kudos
Message 26 of 36
(229 Views)

I am trying to repurpose code given by altenbach that groups a 1d array into a 2d array such that it can handle a new input consisting of a 2d array and 1d arrray providing the same output. The 2D array will contain the same elements as the previous 1D array but in different locations. The 1d array will contain the column index which the element should be placed in. As seen in the figure, the column starting index. The elements that appear in the same row are grouped if the letter matches and if their intervals overlap or are within the max distance. The input will always be letter [starting point -  end point]. 

 

Asasafuchi_2-1736322412611.png

I have attached the vi that handles the 1d case with the new example inputs. I am sure there is an easy way to solve it but I just cant figure out how.

0 Kudos
Message 27 of 36
(193 Views)

Ok I think I solved it, however I would like to change the first bundling process such that it does not rely on the input being an uppercase letter and can handle words. Is there an easy way to change the bundling algorithm such that it checks the entire word and not just the first character? Because right now it will group if the first character is a match.

0 Kudos
Message 28 of 36
(171 Views)

Sorry, I've been without power since last evening. No computer access.

 

Parsing the string should be easy, e.g. just find the "[" and go from there.

 

0 Kudos
Message 29 of 36
(166 Views)

No worries 🙂

Could I not just replace the string to unsigned bit array with a match regular expression, looking for the brackets and then use that to find the index? Also, what is the purpose of converting from string to ascii index? Would it not work with searching for the character themself?

Asasafuchi_0-1736406695376.png

 

0 Kudos
Message 30 of 36
(150 Views)