08-07-2009 02:59 PM
I created a one dimensional array whose elements are clusters.
Each cluster consists of two elements. The elements are integers.
For example: [256 4569]
Now I want to search for a cluster whose first element is for example "24".
How can I do that ? Is there a specific VI ? Can I use the "1D Array Search VI" ?
Yes, I know I could use a two dimensional array.
But think more general.
What if there are different data types, not only integers ?
08-07-2009 03:16 PM
The Search 1D Array function requires you to wire the same datatype as the datatype of the elements of the array. Thus, you would need to wire a cluster of 2 integers. It performs an exact match search, so you cannot create a cluster of two integers where the first one is 24 and the other is 0. Unless you have an element with the values [24 0] in your array you would get no match. What you have to do is to unbundle the cluster using a for-loop to get the first element so you can search that array:
08-07-2009 03:30 PM
Something like this, perhaps? You can look for a specific value of a specific element of a cluster if you compare aggregates. If you are looking for one value in one cluster in an array of clusters just run the array through a loop.
08-07-2009 03:54 PM - edited 08-07-2009 03:55 PM
I'm not sure if you're responding to my post, or to the OP. If it's to me I think you misunderstood what I was saying. What I understood the OP to want is to look for the array element in which the first number is 24, without specifying the second number. The "compare aggregates" option does nothing for you in this case. Given this, you obviously can't provide a cluster element to the Search 1D Array in which the first value is 24 and the other is (for example) 0. The Search 1D Array doesn't do a match on only the first cluster element.
I also have no idea why you're using a loop with a shift register with an Array Size function and an Index Array as opposed to simply using auto-indexing. Assuming that's the way you'd want to do it. It would actually be simpler to just do this:
Of course, the above will return False, since the array has no [24 0] element in it.
08-07-2009 04:04 PM
Perhaps you should add your vote to the following ideas:
08-07-2009 04:17 PM
Thanks Paul.
So its like in any other programming language.
I need a for loop.
08-07-2009 04:27 PM
08-07-2009 07:43 PM - edited 08-07-2009 07:45 PM
HansWerner wrote:Now I want to search for a cluster whose first element is for example "24".
Reading this, I don't think Paul's interpretation is correct.
Here's yet another alternative which does not need any intermediary arrays. 😉
08-07-2009 07:52 PM - edited 08-07-2009 07:53 PM
altenbach wrote: ... and assumes there is at least one match!
Here we solve the problem to return -1 if no match is found.
08-08-2009 09:06 AM