0

This might be a basic question.

To find out the maximum value and its index in array in MATLAB, I have used this code:

A = [1 2 3; 4 5 6; 7 8 9]

[val, idx] = max(A, [], 2);

Now, how can I find the index array of all the element (not finding maximum)?

ShadowWarrior
  • 180
  • 1
  • 12

1 Answers1

0

May be you are talking bout subindices and global indices. Read about sub2ind and ind2sub. Check the below demo:

A = [1 2 3; 4 5 6; 7 8 9] ;

[m,n] = size(A) ;

% sub indices 
[J,I] = meshgrid(1:m,1:n) ;
% global indices 
idx = sub2ind(size(A),I,J)
Siva Srinivas Kolukula
  • 1,251
  • 1
  • 7
  • 14