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

  • Context: MATLAB 
  • Thread starter Thread starter joanne34567
  • Start date Start date
  • Tags Tags
    Matlab Matrix Max
Click For Summary
SUMMARY

To find the maximum and minimum values of a specific column in a matrix using MATLAB, utilize the built-in functions max and min. For a matrix X with 100 rows and 4 columns, access the 4th column with X(:,4). The command [Y,I] = max(X(:,4)) retrieves the maximum value Y and its index I. To extract the entire row corresponding to the maximum value, use X(I,:).

PREREQUISITES
  • Basic understanding of MATLAB syntax
  • Familiarity with matrix operations in MATLAB
  • Knowledge of indexing in MATLAB
  • Experience with MATLAB built-in functions
NEXT STEPS
  • Explore MATLAB documentation on help max and help min
  • Learn about advanced indexing techniques in MATLAB
  • Investigate MATLAB's data visualization tools for matrix analysis
  • Study performance optimization techniques for large matrices in MATLAB
USEFUL FOR

Data analysts, engineers, and researchers who work with matrices in MATLAB and need to extract specific statistical values from their datasets.

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 4 ·
Replies
4
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
7
Views
2K