LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to search a 1D array for a cluster ?

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 ?

0 Kudos
Message 1 of 13
(8,293 Views)

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:

 

0 Kudos
Message 2 of 13
(8,281 Views)

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.

 

Example_VI_BD.png

PaulG.
Retired
Message 3 of 13
(8,272 Views)

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:

Example_VI_BD.png

 Of course, the above will return False, since the array has no [24 0] element in it.

Message Edited by smercurio_fc on 08-07-2009 03:55 PM
Message 4 of 13
(8,259 Views)

Thanks Paul.

 

So its like in any other programming language.

I need a for loop.

0 Kudos
Message 6 of 13
(8,239 Views)
Let's be clear: Paul's solution will not work if you only want to match the first element. Is that the case? If so, you have to do what I showed you in my first response. If, on the other hand, you want to find the element in which you want to match both elements of the cluster, then Paul's solution is the Rube Goldberg method of doing what I showed you in my reply #4.
0 Kudos
Message 7 of 13
(8,230 Views)

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. 😉

 

 

It will only find the first match and assumes there is at least one match! If you want to find all matches and also handle the case where no match is found, you need to add a little more code. 😉
Message Edited by altenbach on 08-07-2009 05:45 PM
0 Kudos
Message 8 of 13
(8,211 Views)

altenbach wrote: ... and assumes there is at least one match!

Here we solve the problem to return -1 if no match is found.

 

Message Edited by altenbach on 08-07-2009 05:53 PM
Message 9 of 13
(8,205 Views)
One of these days I'm going to remember about LV 8.6 adding the conditional stop on for-loops. Unfortunately, I don't use 8.6 on a daily basis so I will probably remain stuck in the stone age.
0 Kudos
Message 10 of 13
(8,175 Views)