MATLAB: Indices of a maximum value in a multidimensional matrix.

functionsMATLABmatrixmax

Hi, I have a multidimensional matrix of size (100,16,4,10) and i want to calculate all the 4 indices of the max value in it? Any help please.

Best Answer

  • a=rand(100,16,4,10); %Example
    [max_value,idx]=max(a(:))
    [x,y,z,w]=ind2sub(size(a),idx)
    If the dimension of a is unknown
    a=rand(100,16,4,10);
    [max_value,idx]=max(a(:))
    x=cell(ndims(a),1)
    [x{:}]=ind2sub(size(a),idx)