how to find matrix indices

2 views (last 30 days)
sowndharya
sowndharya on 8 Mar 2013
k=1:2; t=1:2; x(k,t)=[1.2 1.3;1.8 1.5] max(x) I have entered input x and found max(x).For what value of k and t , x is maximum ?How to find this using matlab code?

Accepted Answer

Wayne King
Wayne King on 8 Mar 2013
Edited: Wayne King on 8 Mar 2013
Do you want the single biggest element in the matrix? If so then, just max() will not give you that. You'll get a row vector of the largest elements in each column.
X = [1.2 1.3;1.8 1.5];
[val,idx] = max(X(:));
[I,J] = ind2sub(size(X),idx);
X(I,J)
is the largest element.
  1 Comment
sowndharya
sowndharya on 14 Mar 2013
I want max value in every column so i have used max command .That was helpful.but i want to find the next maximum value in all the columns.This process have to be repeated till finding the least value in that column.i mean in descending order.for ex x=[1 2 3;4 5 6;7 8 9] max(x) will give (1 4 7) [x,y]=max(x) y gives (1 1 1) (indices)
next i have to find next max (2,5,8) the indices i should get (2 2 2) what command i should use?

Sign in to comment.

More Answers (0)

Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!