How does one find the max value of one column and relate it to another column?

8 visualizzazioni (ultimi 30 giorni)
Hi there,
How does one determine the max value of one column and relate it to another column.
For example: Max value of "ace" column matched with "year" column.
Thanks!

Risposte (1)

John D'Errico
John D'Errico il 27 Feb 2022
Read the help for max. What are the outputs?
help max
MAX Maximum elements of an array. M = MAX(X) is the largest element in the vector X. If X is a matrix, M is a row vector containing the maximum element from each column. For N-D arrays, MAX(X) operates along the first non-singleton dimension. When X is complex, the maximum is computed using the magnitude MAX(ABS(X)). In the case of equal magnitude elements the phase angle MAX(ANGLE(X)) is used. [M,I] = MAX(X) also returns the indices corresponding to the maximum values. The values in I index into the dimension of X that is being operated on. If X contains more than one element with the maximum value, then the index of the first one is returned. C = MAX(X,Y) returns an array with the largest elements taken from X or Y. X and Y must have compatible sizes. In the simplest cases, they can be the same size or one can be a scalar. Two inputs have compatible sizes if, for every dimension, the dimension sizes of the inputs are either the same or one of them is 1. M = MAX(X,[],'all') returns the largest element of X. [M,I] = MAX(X,[],'all') also returns the linear index into X that corresponds to the maximum value over all elements in X. M = MAX(X,[],DIM) or [M,I] = MAX(X,[],DIM) operates along the dimension DIM. M = MAX(X,[],VECDIM) operates on the dimensions specified in the vector VECDIM. For example, MAX(X,[],[1 2]) operates on the elements contained in the first and second dimensions of X. C = MAX(X,Y,NANFLAG) or M = MAX(X,[],...,NANFLAG) or [M,I] = MAX(X,[],NANFLAG) or [M,I] = MAX(X,[],DIM,NANFLAG) specifies how NaN (Not-A-Number) values are treated. NANFLAG can be: 'omitnan' - (default) Ignores all NaN values and returns the maximum of the non-NaN elements. If all elements are NaN, then the first one is returned. 'includenan' - Returns NaN if there is any NaN value. The index points to the first NaN element. [M,I] = MAX(X,[],...,'linear') returns the linear index into X that corresponds to the maximum value in X. C = MAX(...,"ComparisonMethod",METHOD) specifies how to compare input values. The value of METHOD must be: 'auto' - (default) Compares real numbers according to 'real', and complex numbers according to 'abs'. 'real' - Compares according to REAL(A). Elements with equal real parts are then sorted by IMAG(A). 'abs' - Compares according to ABS(A). Elements with equal magnitudes are then sorted by ANGLE(A). Example: X = [2 8 4; 7 3 9] max(X,[],1) max(X,[],2) max(X,5) See also MIN, BOUNDS, CUMMAX, MEDIAN, MEAN, SORT, MAXK, ISLOCALMAX. Documentation for max doc max Other functions named max categorical/max dlarray/max gpuArray/max tall/max codistributed/max duration/max sym/max timeseries/max datetime/max fints/max
Do you see the SECOND output argument from max? That tells you where the maximum occurs, at which index.
Use that returned argument to index into your other vector.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by