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

  • Topic: MATLAB 
  • Thread starter Thread starter joanne34567
  • Start date Start date
  • Tags Tags
    Matlab Matrix Max
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
1 reply · 15K views
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.