find indices of a value in a particular row or column in relation to the full matrix

1 view (last 30 days)
Hi,
I am trying to find the location of the max and min values of the first row and last column of an array. Let's say I have the following matrix: A=[1,2,3,4,5;,6,7,8,9,10;11,12,13,14,15;16,17,18,19,20;21,22,23,24,25]. I want to find the location of the max and min values in the first row and last column. By looking at this matrix we can easily see that it is the first number (or x = 1, y = 1,assuming that x is columns and y is rows), the last number in the first row (x = 5, y = 1) and the last number in the last column (x = 5, y = 5). My question is if we are using the find command to find the max and min in particular rows and columns, is how to relate this location in the column or row to the larger array.

Accepted Answer

Image Analyst
Image Analyst on 27 Apr 2017
Why use find() when min() and max() are more directly suited for finding the min and max values and indexes:
A=[1,2,3,4,5;,6,7,8,9,10;11,12,13,14,15;16,17,18,19,20;21,22,23,24,25]
[firstRowMaxValue, firstRowMaxIndex] = max(A(1, :))
[firstRowMinValue, firstRowMinIndex] = min(A(1, :))
[lastColMaxValue, lastColMaxIndex] = max(A(:, end))
[lastColMinValue, lastColMinIndex] = min(A(:, end))

More Answers (0)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!