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?

 Akzeptierte Antwort

Guillaume
Guillaume am 19 Jan. 2015

1 Stimme

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 Kommentare

Jason
Jason am 19 Jan. 2015
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.
dpb
dpb am 19 Jan. 2015
max([Cam2G(:); Cam2Gb(:)])
NB: used (:) to ensure both are column vectors; use concatenation as appropriate to the storage direction.
Jason
Jason am 19 Jan. 2015
thankyou

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

dpb
dpb am 19 Jan. 2015

1 Stimme

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

1 Stimme

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

Kategorien

Gefragt:

am 19 Jan. 2015

Kommentiert:

am 19 Jan. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by