1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab max and min of a matrix

  1. Oct 1, 2011 #1
    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?
     
  2. jcsd
  3. Oct 2, 2011 #2
    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Matlab max and min of a matrix
  1. Max min trig functions (Replies: 5)

Loading...