finding indexed values of vector

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

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

Thats great, thankyou. If now i have set of the two max values for Cam2G and do the same for another data set Cam2Gb, so now there are 4 max values. How do I find the overall max, I tried:
max(max(Cam2G, Cam2Gb))
i get
Error using max
Too many input arguments.
max([Cam2G(:); Cam2Gb(:)])
NB: used (:) to ensure both are column vectors; use concatenation as appropriate to the storage direction.
thankyou

Sign in to comment.

More Answers (2)

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

Asked:

on 19 Jan 2015

Commented:

on 19 Jan 2015

Community Treasure Hunt

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

Start Hunting!