MATLAB: Array Mode Max Find

mode

I need to consider the case in which the maximum is a mode.
With
A = [1 1 1 1 6 7 7 1 1 3 5 6 7 7 1 1 3 5 6 7 7 1 1 3 5 6 7 7];
I need to get the indices for the max, which I have tried and it worked but suppose I have repeated minimum and for some reason it gives me more indices than needed.
So as I said, so oink should be returning:
6 13 20 27
but instead I get
1 6 8 13 15 20 22 27
[m,f,c] = mode(A); Tmode = max(c{1})
Tmax = max(A); if Tmax == Tmode
oink = find(diff(A)==0); % <----- the problem occurs here
test_idx = [1;oink];
else
label = [find(A==max(A))];
test_idx = [1;label];
end
The last condition doesn't pose a problem, it's the first. The problem would arise if I have both two repeated min and max. find(diff(A)==0) would return both. Is there a way around this?
Now suppose I have a vector with distinct elements A = [ 1 2 3 4 5 6]
c would return as the entire array. This is not what I want.
It would fail from :
[m,f,c] = mode(A);
Tmode = max(c{1})
If I had just taken Tmode = mode(A) then it would work but not progress to the first case.
Any advice?

Best Answer

I'm not sure if I understand the question. Are you looking for:
A = [1 1 3 5 6 7 7];
[value, index] = max(A)
?
Related Question