[r,c] =min(A) not returning index values

5 ビュー (過去 30 日間)
Colin Tyznik
Colin Tyznik 2018 年 9 月 6 日
編集済み: Greg 2018 年 9 月 6 日
I am running into an issues using the [r,c] = min(A) command. I am using this with the intent of finding the row and column index of the minimum value element of the array.
instead, r is a vector of the lowest value element from each column, and c returns what row index of each value is. I am a little confused on what is going on.
  3 件のコメント
Colin Tyznik
Colin Tyznik 2018 年 9 月 6 日
Whoops. totally misread that initially. its evidently too late to troubleshoot matlab code. thanks very much.
Greg
Greg 2018 年 9 月 6 日
Ahh, the I'm up way too late but gotta get this finished, and now I'm making silly mistakes. We've all been there. Good luck.

サインインしてコメントする。

回答 (1 件)

Greg
Greg 2018 年 9 月 6 日
編集済み: Greg 2018 年 9 月 6 日
So the documentation fairly clearly states that output one is an array containing the minimum values, and the second output is the index of the first occurrence of each minimum value.
What might not be immediately obvious is that output two is exactly one dimension lower than the input (as opposed to 2 dimensions reduced). In your 2D example, "c" is a row vector that gives the row number of each column's minimum value location. You don't need a vector of column indices, because the column position in "c" is the column index of that min value. You're guaranteed a minimum value for each column, so the c array you wanted is simply 1:#columns.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by