10-18-2021 10:54 AM
plz any suggestion how to solve this :
If the array has an even number of elements, then use (N/2) as the middle element. For example, if the array has
ten elements then the middle-most would be (10/2) = 5 or the 5th element in the array. If the array has an odd number of elements, then the middle will be (N/2) + 0.5. For example, if the array has
seven elements then the middle-most would be (7/2) + 0.5 = 4 or the 4th element in the array.
10-18-2021 11:31 AM - edited 10-18-2021 12:17 PM
See if this meets your requirements.
The Ramp Pattern stuff was just to make an easy array to verify the rest of the code worked.
10-18-2021 12:01 PM
Hi jiji,
@jiji_830 wrote:
- If the array has an even number of elements, then use (N/2) as the middle element. For example, if the array has
ten elements then the middle-most would be (10/2) = 5 or the 5th element in the array.- If the array has an odd number of elements, then the middle will be (N/2) + 0.5. For example, if the array has
seven elements then the middle-most would be (7/2) + 0.5 = 4 or the 4th element in the array.
10-18-2021 12:53 PM - edited 10-18-2021 01:01 PM
I'm not sure where you are having problems -- with the concept of "middle of the array", with the "decision-making" that is described in the algorithm you posted, or "how to program" such an algorithm.
Personally, I think the biggest issue is "What is the middle element of a discrete ordered set of data"? If I hold up three finger, I think all reasonable people will agree that the second finger, with one finger on either side, is the "middle" finger. What if I hold up 4 fingers? Is it the second? Is it the third? What is meant by "middle"?
In statistics, there is the concept of the "mean", or "average". If I number my fingers 1, 2, 3, ..., and take the mean of the 3 finger numbers, I'll compute (1+2+3)/3 = 6/3 = 2. If I do this for only 2 fingers, I will compute (1+2)/2 = 1.5, which is exactly half-way between 1 and 2. But if I restrict myself to integers (because I want to identify the "middle finger"), I am forced to use an integer, so I "adopt a convention" and round up, or round down (depending on what convention I choose).
Let's number the elements (or "fingers") starting with 1 and numbering 1, 2, 3, ... How do we find the "average" (= "middle") value? Simply sum the series and divide by the number of entries. Do you remember from High School Algebra the formula for 1+2+...+n? It is n*(n+1)/2. If we divide by n, we get the "middle" as (n+1)/2, which is an Integer if n is odd.
Sometimes the more interesting questions are the ones that don't get asked ...
Bob Schor
10-18-2021 01:01 PM
@jiji_830 wrote:
plz any suggestion how to solve this :
If the array has an even number of elements, then use (N/2) as the middle element. For example, if the array has
ten elements then the middle-most would be (10/2) = 5 or the 5th element in the array. If the array has an odd number of elements, then the middle will be (N/2) + 0.5. For example, if the array has
seven elements then the middle-most would be (7/2) + 0.5 = 4 or the 4th element in the array.
You are making a sequence of incorrect statements and I am not sure what you consider "solve this". (implement the faulty math in LabVIEW? Come up with better definitions?)
As others have said, a 1D array with an even number of elements has no middle element, but you can of course do a linear interpolation between the two values adjacent to the middle. A 1D array with an odd number of elements has a clear middle. In all cases, the indices of the interesting element can be calculated from the array size.
10-18-2021 01:12 PM
I feel like this was a school assignment and the problem statement was copy-pasted. Such that the "middle" element here is defined exactly how the problem statement says, much to all of our dismay.
Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.
10-18-2021 01:18 PM
"Interpolate array" will correctly interpolate for fractional indices, so this will give the value of the middle element (size=odd), or the average of the two elements adjacent to the middle (size=even).
10-18-2021 01:32 PM
thank u all for ur clarification. i miss understanding the problem now I got an idea. i will fixe it. thank u all so much