LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

"Intelligent" unique array

Solved!
Go to solution

Hello,

 

I have several arrays (grouped inside a cluster) with two columns : header is in the first column, value in the second column.

Capture d’écran 2018-05-20 à 18.36.04.png

 

I want to have an array with only unique headers, and values.

 

Capture d’écran 2018-05-20 à 18.38.49.png

 

I manage to have unique headers, but the problem is unique data. I've attached the VI. I think the problem may come from "insert into array" which I believe cannot insert on a row that doesn't exists yet?! Can you help me?

 

 

 

 

 

0 Kudos
Message 1 of 10
(3,101 Views)

finally, with two succesive for loops and a bit of Gcode...

0 Kudos
Message 2 of 10
(3,076 Views)

Thanks for posting the solution. Haven't looked at it, but if your problem is solved please accept your post solution.

0 Kudos
Message 3 of 10
(3,062 Views)

One problem is that you represent integers as strings, so an alphabetic sorting of the numbers of each row will not be sorted numerically. Do you care about the sort order of the numbers in each row? If not, a variant attribute based solution is especially simple, but with a few minor tweaks in can also be adapted for the numerically sorted case.

 

Message 4 of 10
(3,059 Views)
Solution
Accepted by topic author haha1234

@altenbach wrote:

 If not, a variant attribute based solution is especially simple,


Here's how that could look like.

GetUnique.png

 

 

(To sort the numbers numerically, you could do a "string to numeric--sort--numeric to string" before the lower input of the last "built array". If you would zero-pad the numeric strings so all have the same length, you would not have this problem. Modify as needed).

Message 5 of 10
(3,035 Views)

Hello,

 

thank you you all for your contributions.

 

The values 1, 45, 7... are just examples. They can be string, integer, double, that’s why I used string by default. I don’t care about the order, I just don’t want any blanks.

 

altenbach, your variant example is very interesting I will study it as I was not aware of this possibility. It seems to be more efficient.

 

but... imagine I care about the order ? Is there a way to do an alphanumerical sort (just like files in windows folders)? Example 11 before 99 before A1 before B1 before B2 etc...

 

regards

 

 

0 Kudos
Message 6 of 10
(3,019 Views)

As Suggested earlier "Variant Attribute" will be the easy way of handling to collect data of specific header, Once its data is collected you can sort the array (wrt. Header) of your choice.

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 7 of 10
(3,010 Views)

@haha1234 wrote:

 

but... imagine I care about the order ? Is there a way to do an alphanumerical sort (just like files in windows folders)? Example 11 before 99 before A1 before B1 before B2 etc...

 


The variant attribute method will always be sorted alphabetically. No extra code needed for your examples. However "11" will be before "2" unless you call it "02"..

 

Windows explorer (in newer versions of windows!) will do a mixed mode if parts of the file name are numerical. You would need to implement that yourself. I already mentioned where that sorting step would go.

0 Kudos
Message 8 of 10
(2,988 Views)

OK I understand.

 

However, I noticed a small problem. If I have an empty string after the header instead the number, there is an error when the VI tries to set the attribute to the variant.

 

Is it normal ? Is there a workaround ?

0 Kudos
Message 9 of 10
(2,963 Views)

Yes, empty strings are not allowed for attribute names. Simply use a case structure and bypass that code (or just ignore the error)

0 Kudos
Message 10 of 10
(2,956 Views)