# HP -28S Manual Page 275

After all medians are calculated and positioned correctly on the
stack, they're combined into a vector.
• FOR ... NEXT (definite loop with counter). MEDIAN uses a loop to
calculate the median of each column. Because the medians are cal-
culated in reverse order (last column first), the counter is used to
reverse the order of the medians.
Required Programs:
• SORT (page 270) arranges a list in ascending order.
• LMED (page 272) calculates the median of a sorted list.
Program
«
RCU:
DUP SIZE
LISH DROP
~
n m
«
I
:mAT
I
TRN
1
m
FOR
j
};-
ARRY~
DROP
n
~LIST
SORT
LMED
Begin the program.
Put a copy of the current statis-
tics matrix 2:DAT on the stack for
safekeeping.
Put the list {
n m }
on the stack,
where
n
is the number of rows in
2:DAT and
m
is the number of
columns.
Put nand
m
on the stack. Drop
the list size.
Create local variables for nand
m.
Begin the defining program.
Transpose 2:DAT. Now n is the
number of columns in 2:DAT and
m
is the number of rows.
The first and last rows.
For each row, do the following:
Extract the last row in 2:DAT. Ini-
tially this is the
mth row, which
corresponds to the
mth column in
the original 2:DAT.
Put the row elements on the
stack. Drop the index list {
n },
since
n
is already stored in a local
variable.
Make an n-element list.
Sort the list.
Calculate the median of the list.
274
28: Programming Examples  