How would one find the minimum value in each row, and also the index of the minimum value?
octave:1> a = [1 2 3; 9 8 7; 5 4 6]
a =
1 2 3
9 8 7
5 4 6
How would one find the minimum value in each row, and also the index of the minimum value?
octave:1> a = [1 2 3; 9 8 7; 5 4 6]
a =
1 2 3
9 8 7
5 4 6
This is hard to find in the documentation. https://www.gnu.org/software/octave/doc/v4.0.3/Utility-Functions.html
octave:2> [minval, idx] = min(a, [], 2)
minval =
1
7
4
idx =
1
3
2
>help min
in octave... You see Built-in Function: min (X, [], DIM)
and also a long, detailed explanation that explains what you want. So, not hard to find :p –
Malamut doc min
. A Google search on octave min
also took me right to the link you posted. –
Humanize If A is your matrix, do:
[colMin, row] = min(A);
[rowMin, col] = min(A');
colMin will be the minimum values in each row, and col the column indexes. rowMin will be the minimum values in each column, and row the row indexes.
To find the index of the smallest element:
[colMin, colIndex] = min(min(A));
[minValue, rowIndex] = min(A(:,colIndex))
Suppose X is a matrix
row, col = Row and Column index of minimum value
[min_value, column_index] = min(X(:))
[row, col] = ind2sub(size(X),column_index)
Given a matrix A of size m x n, you need to find the row number for the smallest value in the x column.
e.g A is 64x3 sized;
search_column = 3;
[val,row] = min(results(:,search_column),[],1);
#row has the row number for the smallest value in the 3rd column.
Get the values for the first and second columns for the smallest row value
column1_value = A(row,1);
column2_value = A(row,2);
© 2022 - 2024 — McMap. All rights reserved.
help min
says "If called with one input and two output arguments,min
also returns the first index of the minimum value(s). Example[x, ix] = min ([1, 3, 0, 2, 0])
" – Beutler