Find indexs of minimum in 4-D matrix.

16 ビュー (過去 30 日間)
Clément Métayer
Clément Métayer 2020 年 5 月 10 日
コメント済み: Steven Lord 2020 年 5 月 10 日
Hi im trying to find the indexs of the minimum in a 4-D "matrix" but the usual command:
[Minimum,Index]=min(Expression,[],'all') does not work.
(here "Expression" is my function of 4 variables )
The error message tells me : Error using min
Specify 'linear' option when returning two outputs and the dimension is 'all' or a vector.
But when i specify the linear option it returns me the index 11755218 and i don't understand what it means ?
Note: the ndgrid of my function is :[phi1,phi2,phi3,phi4]=ndgrid(0:0.1:2*pi,0:0.1:2*pi,0:0.1:2*pi,0:0.1:2*pi);
Thx to the great saouls who can help me.
  1 件のコメント
Steven Lord
Steven Lord 2020 年 5 月 10 日
Walter has showed you how to get what you're looking for. But to answer your question (what 11755218 means) that is the linear index to the element whose value is returned as Minimum. See the "Indexing with a Single Index" section on this documentation page for an explanation of linear indexing.
A = reshape(1:24, [4 2 3])
A(15)
A(3, 2, 2)
Element (3, 2, 2) of A is also element 15 of A.

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

採用された回答

Walter Roberson
Walter Roberson 2020 年 5 月 10 日
編集済み: Walter Roberson 2020 年 5 月 10 日
[Minimum, Index] = min(Expression, [], 'all', 'linear')
[idx{1:ndims(Expression)}] = ind2sub(size(Expression), Index);
[idx{:}]
Though perhaps what you want is instead
[Minimum, Index] = min(Expression, [], 'all', 'linear')
[phi1(Index), phi2(Index), phi3(Index), phi4(Index)]
  1 件のコメント
Clément Métayer
Clément Métayer 2020 年 5 月 10 日
Thanks you so much for your answer it works well !!!
Yes the second is the rgiht one that i was looking for.
Thx walter

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

その他の回答 (1 件)

Gifari Zulkarnaen
Gifari Zulkarnaen 2020 年 5 月 10 日
Maybe linear means the index ordered in from high dimension to one dimension. For example, for 2D matrix with 2 rows and 3 columns:
example2D = [3 2 1; 4 5 6];
[minValue,minIndex] = min(example2D,[],'all','linear');
Here minIndex = 5 means row 1 and column 3 (2x2+1).
For your case also, Expression(Index) is equal to Minimum.

カテゴリ

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