How to sort a n by 1 dimensional matrix and after sorting get the initial index of a value?

How to sort a list and get the initial index of a value in matlab.

e.g
orignal A=[40;30;20;50;60]
sorted A=[20;30;40;50;60]
indices of sorted A in orignal A =[3;2;1;4;5] 

Answers


Simple:

[sorted, indices] = sort(A);


You can use the second output:

   [~,i]=sort([40;30;20;50;60])

The tilda means that the first output is ignored.


Need Your Help

TabHost containing a tabwidget that does not start a activity

android android-activity tabs

I have 4 tabwidgets and when i click the first three of them they must start their respective activities and when I click the fourth tab the layout should be the previous activities on the backgrou...

Capture IE resource requests

internet-explorer http networking proxy

I am trying to create a custom HTTP request/response logger for Internet Explorer. In my application I have an embedded browser object. I have a pointer to IWebBrowser2 interface. This interface has