locating the relative position of a value in a 2 x matrix

I have a 180 by 180 matrix and want to locate the position of the minimum value so I can subsequently reuse the source variables used in the creation of that matrix.
i.e. the minimum valur occurs at row 10 and column 130 but I have not been able to simply return those two numbers.

 採用された回答

Daniel Shub
Daniel Shub 2012 年 5 月 22 日

0 投票

x = randn(180);
[~, I] = min(x(:));
[I, J] = ind2sub(size(x), I);

その他の回答 (3 件)

David
David 2012 年 5 月 22 日

0 投票

Thanks - I would not have intuited this from MatLab's limited documentation.
Daniel Shub
Daniel Shub 2012 年 5 月 22 日

0 投票

From an understanding point, maybe this is better
x = randn(180);
[y, I] = min(x);
[~, J] = min(y);
[I(J), J]
David
David 2012 年 5 月 22 日

0 投票

Thanks again - both example solutions extend well beyond the simple MatLab documentation.
My key takeaways from the first solution frame an understanding / confirmation regarding the second. The use of the wild card (:) unlocks some of my road blocks as does the realization that the first index is a linear index that must be converted into row and column designations.

カテゴリ

ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by