obtain column value for lowest element in each row of an 2D array

1 回表示 (過去 30 日間)
Koule Pantazopoulos
Koule Pantazopoulos 2018 年 8 月 30 日
I have a 2D array 20 X 10 double. Each row has a lowest figure. I am trying to obtain the column value of the minimum element in each row. I do not need the row value, just the column value. I have searched an been able to find the minimum value but the forums do not show a way of obtaining individual row or column figures for a set value. Assistance appreciated
  7 件のコメント
Koule Pantazopoulos
Koule Pantazopoulos 2018 年 8 月 30 日
Is there any way of using this solution with fprintf?
Stephen23
Stephen23 2018 年 8 月 30 日
"Is there any way of using this solution with fprintf?"
fprintf('%d,',idc)
If you want some other formatting then following the guidelines in the fprintf help.

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

採用された回答

Stephen23
Stephen23 2018 年 8 月 30 日
編集済み: Stephen23 2018 年 8 月 30 日
If you want to get the column indices, then this is the second output from min, when you work along the second dimension:
[vec,idc] = min(A,[],2)
For example:
>> A = randi(9,3,4)
A =
3 9 6 3
9 6 3 2
6 3 6 7
>> [vec,idc] = min(A,[],2)
vec =
3
2
3
idc =
1
4
2
vec contains the minimum values for each row. idc contains the corresponding column indices.
  2 件のコメント
Koule Pantazopoulos
Koule Pantazopoulos 2018 年 8 月 30 日
Very elegant. Thank you,
Koule Pantazopoulos
Koule Pantazopoulos 2018 年 8 月 30 日
Thank you again. Very impressed, by your knowledge and speed of response.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by