Matlab max and min of a matrix

In summary, to find the maximum and minimum values of a column in a matrix, you can use the "max" and "min" functions in MATLAB. To specify a specific column, use the syntax X(:,column_number). The functions will return the maximum and minimum values as well as their corresponding indices in the matrix. To access the entire row that contains the maximum or minimum value, use the syntax X(index,:).
  • #1
joanne34567
12
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
  • #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.
 

Related to Matlab max and min of a matrix

1. What is the difference between max and min in Matlab?

The max function in Matlab returns the largest element in a matrix, while the min function returns the smallest element.

2. Can I find the maximum and minimum values in a specific column or row of a matrix?

Yes, you can use the max and min functions along with the index of the desired column or row to find the maximum and minimum values in that specific column or row.

3. How does Matlab handle NaN (Not a Number) values when finding the maximum and minimum?

When finding the maximum and minimum of a matrix, Matlab ignores any NaN values and considers them as non-existent elements.

4. Is it possible to find the index of the maximum or minimum value in a matrix?

Yes, you can use the max and min functions with an additional output argument to return the index of the maximum or minimum value in a matrix.

5. Can I find the maximum and minimum values of a matrix in a specific dimension?

Yes, you can specify the dimension along which you want to find the maximum and minimum values in a matrix by using the 'dim' argument in the max and min functions.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
797
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
897
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
32
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top