MATLAB: Find indexs of minimum in 4-D matrix.

4-d functionindexminimum

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.

Best Answer

  • [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)]