05-20-2018 11:42 AM
Hello,
I have several arrays (grouped inside a cluster) with two columns : header is in the first column, value in the second column.
I want to have an array with only unique headers, and values.
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?
Solved! Go to Solution.
05-20-2018 02:14 PM - edited 05-20-2018 02:16 PM
finally, with two succesive for loops and a bit of Gcode...
05-20-2018 04:55 PM
Thanks for posting the solution. Haven't looked at it, but if your problem is solved please accept your post solution.
05-20-2018 05:41 PM - edited 05-20-2018 05:43 PM
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.
05-20-2018 11:14 PM - edited 11-12-2018 02:00 PM
@altenbach wrote:
If not, a variant attribute based solution is especially simple,
Here's how that could look like.
(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).
05-21-2018 12:58 AM - edited 05-21-2018 01:20 AM
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
05-21-2018 02:04 AM
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.
05-21-2018 08:59 AM
@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.
05-21-2018 01:00 PM
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 ?
05-21-2018 02:06 PM
Yes, empty strings are not allowed for attribute names. Simply use a case structure and bypass that code (or just ignore the error)