Good Morning.
I have a matrix A
A = [87.97 87.97 17.97
95.22 87.96 91.26
75.50 75.50 75.50
78.13 64.89 78.90];
What instructions should I do to get
Minimum value per column
The line and column of that value
The result would be:
magnitude 75.50 64.89 17.97
row 3 4 1
column 1 2 3
Greetings and thanks

 Akzeptierte Antwort

Star Strider
Star Strider am 22 Jan. 2020

0 Stimmen

Try this:
A = [87.97 87.97 17.97
95.22 87.96 91.26
75.50 75.50 75.50
78.13 64.89 78.90];
[MaxA,MaxRow] = max(A)
[MinA,MinRow] = min(A)
producing:
MaxA =
95.2200 87.9700 91.2600
MaxRow =
2 1 2
MinA =
75.5000 64.8900 17.9700
MinRow =
3 4 1

6 Kommentare

Ricardo Gutierrez
Ricardo Gutierrez am 22 Jan. 2020
Hi.
Thanks for your help
Now I need to know the column number where this is the minimum value. How do I do that?
The real matrix is 20 X 18
Find both the row and column of the minimum with the find function:
[RowMin,ColMin] = find(A == min(A(:)))
producing:
RowMin =
1
ColMin =
3
The ‘(:)’ subscript convention forces a column vector, so ‘min(A(:))’ will return the minimum of that column, or the minimum for all of ‘A’. Then all find needs to do is return the row and column indices to it.
To return only the column, the find call becomes:
[~,ColMin] = find(A == min(A(:)))
Ricardo Gutierrez
Ricardo Gutierrez am 22 Jan. 2020
Hi
I only get only the minimum of the columns and I would like to know the minimum of each column.
__________________________________________
clc; clear; close all; format short;
A=[ 87.97 87.97 17.97
95.22 87.96 91.26
75.50 75.50 75.50
78.13 64.89 78.90];
[MinA,MinRow] = min(A)
[~,ColMin] = find(A == min(A(:)))
____________Command Window___________________________
MinA =
75.5000 64.8900 17.9700
MinRow =
3 4 1
ColMin =
3
As always, my pleasure.
The minimum of each column is in the ‘minA’ result:
MinA =
75.5000 64.8900 17.9700
The same is true for the code for the maximum for each column, returned in ‘maxA’.
The maximum row and column for ‘A’ is:
[RowMax,ColMax] = find(A == max(A(:)))
Ricardo Gutierrez
Ricardo Gutierrez am 23 Jan. 2020
This is the code I have, with your suggestions.
______________________________________________
clc; clear; close all; format short;
A=[ 87.97 87.97 17.97
95.22 87.96 91.26
75.50 75.50 75.50
78.13 64.89 78.90];
[MinA,MinRow] = min(A)
[RowMin,ColMin] = find(A == min(A(:)))
__________________________________________________
This is the results show in the Command Window
______________________________________________
MinA =
75.5000 64.8900 17.9700
MinRow =
3 4 1
RowMin =
1
ColMin =
3
ColMin =
3
>>
___________________________________________
As we see it does not show me the columns.
It shows me only one
Already the minimum values and the rows are resolved, only the columns are missing.
Thanks for your help
Star Strider
Star Strider am 23 Jan. 2020
It actually shows everything you want it to show.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 22 Jan. 2020

0 Stimmen

Use the two output form of min(). The second output will be the appropriate row numbers.

3 Kommentare

Ricardo Gutierrez
Ricardo Gutierrez am 22 Jan. 2020
Hi.
Thanks for your help.
With your suggestion I would know the magnitude of the minimum value and the row number it is. Now I need to know in which column this value is.
The actual matrix is 20 X 18
Greetings and thanks
Walter Roberson
Walter Roberson am 23 Jan. 2020
The column number is 1:number of columns
Ricardo Gutierrez
Ricardo Gutierrez am 23 Jan. 2020
Thanks

Melden Sie sich an, um zu kommentieren.

Kategorien

Produkte

Version

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by