Locating global max in 3D plot

I'm working on some MATLAB code but I have encountered a problem that has hindered my progress.
Kindly would you assist me on how I may locate a global maxima value in a case where I have more than one maximas in a 3D plot.
I'm using this
Idx = find((Pmusic(:) == max(max(Pmusic(:)))));
[PmusicmaxRow,PmusicmaxCol] = ind2sub(size(Pmusic), Idx);
but it brings all the maximas but I am only interested with the indices of the global maxima.

 Accepted Answer

Try this:
[maxval,Idx] = max(Pmusic(:));
[PmusicmaxRow,PmusicmaxCol] = ind2sub(size(Pmusic), Idx);
I obviously cannot test this with your matrix, however it worked correctrly when I tested it with my test matrix.

4 Comments

Thank you so much sir for your expert advice. I am trying it but unfortunately, some local maximas are still being considered. I am attaching my code for your kind reference, the code is for determining 2 dimensional direction of arrival (DOA) using MUSIC algorithm. Generally, the estimator part is working well. I am supposed to use the estimated values that are the indices of the maximum spectrum value to calculate RMSE. Kindly, if you may spare sometime to advice me on what the problem maybe.
The max function will only return the first maximum (and the index), in the event that there are more than one. However here, there apopears to be only one maximum.
When I run:
[maxval,Idx] = max(Pmusic(:));
[PmusicmaxRow,PmusicmaxCol] = ind2sub(size(Pmusic), Idx);
maxidxv = find(Pmusic == maxval);
the only maximum value is 18.7194, and the index is 8752. The find call (that I added here temporarily) also only detects the same one maximum, with the same index. The ‘aaa’ and ‘ccc’ vectors are simply repeats of the row and column indices, not new or different indices. So ‘aaa’ is a (1x10) vector of 63, and ‘ccc’ is a (1x10) vector of 48.
There are no local maxima, only one global maximum.
I did not examine all your code, only the part you have questions about, those lines 126 and 127 of the file you attached.
Respected Sir, You are absolutely correct. This section of the code is supposed to genereate indices for the global maximas for 10 iterations and that is the reason ‘aaa’ and ‘ccc’ are (1x10) vectors. Thank you so much for your invalauble advice. You have made me move a step further with my work.
As always, my pleasure!
I am always happy to help!

Sign in to comment.

More Answers (0)

Categories

Find more on Beamforming and Direction of Arrival Estimation 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!