05-24-2007 06:32 AM
05-24-2007 06:40 AM
05-24-2007 06:51 AM - edited 05-24-2007 06:51 AM
Message Edited by devchander on 05-24-2007 06:52 AM
05-24-2007 06:52 AM
@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. ![]()
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...
05-24-2007 07:00 AM
05-24-2007 07:04 AM
Hi,
But I have to do it in while loop where it will not work.
Thanks:-
Mike
05-24-2007 07:09 AM
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... ![]()
05-24-2007 07:28 AM
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
05-24-2007 09:08 AM
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.
05-24-2007 09:10 AM - edited 05-24-2007 09:10 AM
"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