Sunday, 8 September 2013

Matlab IF and ELSE, finding multiple max and min values in a matrix

Matlab IF and ELSE, finding multiple max and min values in a matrix

I need some help with the following problem. I have a matrix which could
be of any dimension. I need a code which first find the max and min value
and their corresponding column coordinates of the row for all the columns.
If the max value occurred first, the code will then find the next
occurring min value and respective column coordinate of the row. After the
min value has been found, the code will then find the next max value of
the row and its respective column coordinate. Then the code will then find
the next min value that occurred after the previous max value. The code
will iterate this process until the end of the row and will repeat this
for the remaining rows in the matrix. In the event the min value occurred
first, then the next max value would be recorded. Then the code will find
the next min value along with it column coordinate. Output will be number
not cell format. In the output, values are listed first then column
coordinates listed last. I appreciate your talent and help. Thank you.
Here is an example of the data.
matrix a
1 2 3 4 5 4 4 4 3 2
20 19 19 18 17 16 15 18 19 22
50 50 NaN NaN NaN 60 55 90 NaN NaN
output
1 5 2 1 5 10
20 15 22 1 7 10
50 60 55 90 1 6 7 8

No comments:

Post a Comment