LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

find index of array element

Hi,
            I am trying to find the index of an array element. User will enter start number and end number. I have to search the array in such a way that if start number is less than 1st index element the start index should be 0 or else I have to search the next index element until I find the element which is greater than or equal to start number and this is the start index.
            Similar is for the end index if end number is greater than last index number of array then my end index will be last index of array otherwise I have to search the element in array until I find element which is less than or equal to end number.
            I am attaching the vi along with it which is incomplete. Please complete the vi to get above result.
 
 
Thanks:-
Mike 
0 Kudos
Message 1 of 10
(58,617 Views)
Check the functional description of the "Threshold 1D Array" function. I think it will do most of what you need.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 2 of 10
(58,605 Views)
Since I have a older version of LabVIEW on my system, I could not take a look at your vi.
 
But from what I understand, would not an 'Array subset' function do what you want??
'index' input for 'start number', ' length' input for 'end number'
You get a required subset
 
Now do your indexing for an element in that subset, using 'index array' function

Message Edited by devchander on 05-24-2007 06:52 AM

0 Kudos
Message 3 of 10
(58,601 Views)


@MikeMike wrote:
Hi,
            I am trying to find the index of an array element. User will enter start number and end number. I have to search the array in such a way that if start number is less than 1st index element the start index should be 0 or else I have to search the next index element until I find the element which is greater than or equal to start number and this is the start index.
            Similar is for the end index if end number is greater than last index number of array then my end index will be last index of array otherwise I have to search the element in array until I find element which is less than or equal to end number.


Hi Mike,

I ve LV7.1 only, so cant open your VI. Smiley Sad

From your statement1, do you refer to the value of the 1st index element of the array or the 1st index of the array ? I m puzzled.

If it is the latter case, as I assume, the 1st index of an array is always 0, remember...

So, when the Start value < 1st index, it imploes that the Start value is given as -ve. You ve to set the limits of the Start control from 0 only. Dont allow -ve side nos.

Similar for End value control also.

If it is the former case, then you can use the Search 1D array function for searching the array for both the Start & End values. If either or both are NOT found to be present in the array, this function ll return -1. For this case, you wire 0 as the start index and calculate the array size & wire that value to the End index.

Thats all... Smiley Wink 

- Partha ( CLD until Oct 2027 🙂 )
0 Kudos
Message 4 of 10
(58,599 Views)
See the attached VI in LV7.1, if it helps... Smiley Wink
- Partha ( CLD until Oct 2027 🙂 )
0 Kudos
Message 5 of 10
(58,596 Views)

Hi,

  But I have to do it in while loop where it will not work.

 

Thanks:-

Mike

0 Kudos
Message 6 of 10
(58,595 Views)

Can you come up more of your code ?

Please post a screenshot of it as I ve only LV7.1...

Do you handle 1D or 2D array or more than that ?

I dont find any reason why the code I posted wont work in a while loop... I m bemused... Smiley Surprised

- Partha ( CLD until Oct 2027 🙂 )
Message 7 of 10
(58,588 Views)

Hi Parthabe,

   The the Search 1D array function u use gives the result only if start number is equal to the number in array. What I want is the even if start number is greater than index number then also it should give index.

   Lets take example:- Array ABC={2 ,4, 6,8 ,10 ,14, 17}

  Now if I give start number as a 5 which is not preasent in array list my start index should be 2 (because 5 falls between 4 & 6). How can I do this?

 

Mike

0 Kudos
Message 8 of 10
(58,576 Views)

You've already received the answer to this question in the very first response: Threshold 1D Array. Did you try this? Why don't you try this and then indicate why you don't believe it won't work for you.

Also, we would appreciate it if you would ask for help a bit more nicely than "Please complete the vi to get above result." We might start thinking this is a homework problem.

Message 9 of 10
(58,562 Views)

"You've already received the answer to this question in the very first response: Threshold 1D Array. Did you try this? "

My thoughts exactly!

Ben

Message Edited by Ben on 05-24-2007 09:11 AM

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 10 of 10
(58,559 Views)