Skip to main content
1-Visitor
Solved

pick the middle member of an array

Hello, I have an array of numbers. I don't know the number of members. I want to pick the member at the middle (or close to the middle if the number of members is even).

Is there any function in mathcad for doing this job? Could you help me with this?

Thank you

Werner_E
Werner_EAnswer
25-Diamond I

Something like the built-in function median or something like the "half max index" as shown below?

Note that the value returned by median is not necessarily a number present in the vector but sometimes its the average of the two center values (when the vector is sorted).

15 replies

Werner_E
Werner_E25-Diamond IAnswer
25-Diamond I

Something like the built-in function median or something like the "half max index" as shown below?

Note that the value returned by median is not necessarily a number present in the vector but sometimes its the average of the two center values (when the vector is sorted).

Translate
payman1-VisitorAuthor
1-Visitor

Thank you Werner.

Translate
1-Visitor

An alternative for the condition when you have even members.

Clipboard01.jpg

Mike

Translate
Werner_E
25-Diamond I

Careful! Your routine just returns the index of the elements, not the vector elements themselves.

Translate
1-Visitor

Werner Exinger wrote:

Careful! Your routine just returns the index of the elements, not the vector elements themselves.

Well spotted Werner

Mike

Translate
payman1-VisitorAuthor
1-Visitor

Thank you all gentlemen

Translate