MATLAB How to Find Max and Min of a Matrix Column in Matlab?

  • Thread starter Thread starter joanne34567
  • Start date Start date
  • Tags Tags
    Matlab Matrix Max
Click For Summary
To find the maximum and minimum values of the fourth column in a 4-column, 100-row matrix using MATLAB, the function MAX can be utilized. By specifying the matrix as X, you can isolate the fourth column with the syntax X(:,4). To obtain the maximum value and its corresponding row index, use the command [Y,I] = max(X(:,4)), where Y represents the maximum value and I indicates the row index. To extract the entire row corresponding to the maximum value, use X(I,:). For finding the minimum value, a similar approach applies using the MIN function. This method effectively retrieves both the maximum and minimum values along with their respective row data.
joanne34567
Messages
12
Reaction score
0
Hi, I want to find the maximum and minimum values of a column in a matrix.
I have a 4 column, 100 row matrix and need the minimum and maximum value in the 4th column. I need this to be extracted along with the other values of that row. Can anyone help?
 
Physics news on Phys.org
Try "help max" and "help min."

[Y,I] = MAX(X,[],DIM)

Y is the max value of X taken along the dim- dimension at the index I.

For your case in particular, let X be your matrix. To tell MATLAB to look at the 4th column only you would write X(:,4) which says "X at all rows and the 4th column." Then
[Y,I] = max(X(:,4))
will give you the maximum element Y and the index I in which that occurs. Now the row that corresponds to that maximum is the I-th row. To get the I-th row, write X(I,:) which say "X at the I-th row and all columns"

Hope that helps.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K