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?

 Risposta accettata

Guillaume
Guillaume il 19 Gen 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 Commenti

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.
Jason
Jason il 19 Gen 2015
thankyou

Accedi per commentare.

Più risposte (2)

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

1 voto

But I need to find the index in the unsorted data, not the sorted?

Categorie

Richiesto:

il 19 Gen 2015

Commentato:

il 19 Gen 2015

Community Treasure Hunt

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

Start Hunting!

Translated by