finding indexed values of vector

2 views (last 30 days)
Jason
Jason on 19 Jan 2015
Commented: Jason on 19 Jan 2015
I have a data set that cotnains FWHM. I want to identify the 2 highest values and highlight on a graph. I have used sort rows and picked out the 2 highest values given by Cam2G:
Cam2G =
2.6200
2.5800
If my unsorted data is dataR, how do I get the index in this where the values Cam2G occur?

Accepted Answer

Guillaume
Guillaume on 19 Jan 2015
When you did your sorting, you should have captured the second return value, which is the indices of the sorted values.
dataR = [2.4 2.62 .3 2.5 2.58];
[cam2G, indices] = sort(dataR);
cam2G = cam2G([1 2]);
indices = indices([1 2]);
If somehow, it's too late:
indices = arrayfun(@(v) find(dataR == v, 1), cam2G);
  3 Comments
dpb
dpb on 19 Jan 2015
max([Cam2G(:); Cam2Gb(:)])
NB: used (:) to ensure both are column vectors; use concatenation as appropriate to the storage direction.

Sign in to comment.

More Answers (2)

dpb
dpb on 19 Jan 2015
Use the optional second index return value from sortrows
[mx,imx]=sortrows(FWHM);
Keep the first N of each...

Jason
Jason on 19 Jan 2015
But I need to find the index in the unsorted data, not the sorted?

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!