PLEASE HELP ME find coresponding column indexes.

I have a matrix V of size (3x3) and another matrix W (3x3), where off-diagonals are zero in matrix W and diagonals are non-zero. Then I have A=sort(diag(W)). Now I want to get the corresponding column index number from matrix W.
CODE IS GIVEN BELOW:
V= [3 4 5; 4 7 8;2 6 1];
W=[5 0 0;0 7 0;0 0 2];
A=sort(diag(W));
A =
2
5
7
Now i want the corresponding column index number. for example: in this problem first element is 2 and corresponding column index number 3 from matrix W. Similarly for 5 is 1 and for 7 is 2 respectively.

5 Kommentare

‘Now i want to get the corresponding column index number from matrix W.’
Corresponding to what?
Stephen23
Stephen23 am 4 Jan. 2015
Please edit your question.
  • Format the code so that it is readable (use the {} Code button above the text box)
  • Describe the problem in more detail (as Star Strider has already pointed out)
  • Don't put three sentences in the title.
  • Read this:
palash de
palash de am 4 Jan. 2015
corresponding to sorted elemnt
Image Analyst
Image Analyst am 4 Jan. 2015
Bearbeitet: Image Analyst am 4 Jan. 2015
Do you mean the rows and columns of V that correspond to values in A? Is so, why even bother to sort W? And what if the numbers in W don't appear in V? read this
Stephen23
Stephen23 am 4 Jan. 2015
Interestingly you don't refer to matrix V at all. Is this intentional?

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Stephen23
Stephen23 am 4 Jan. 2015
Bearbeitet: Stephen23 am 4 Jan. 2015
If you read the documentation for the sort function, you will find that there is a second output giving the indices of the sort. Your code would become:
[A,I] = sort(W)
Try that, and it might be useful for solving your problem.

3 Kommentare

True enough, but sorting a diagonal matrix ... ?
Stephen23
Stephen23 am 4 Jan. 2015
Yes, the whole thing is a bit fishy... hopefully the OP can provide some more information on what they really are trying to achieve.
palash de
palash de am 4 Jan. 2015
Thank you so much Stephen

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by