# Find maximum among the elements in the matrix lower than 80% of max element of entire matrix

4 views (last 30 days)
Ivan on 14 Oct 2020
Commented: Fangjun Jiang on 14 Oct 2020
Hi!
I have a matrix A(n,n). I determine the maximum element like S=max(A(:)).
Now, I would like to find the maximum element only among the elements of the matrix A which are lower than 0.8*S.
Could you suggest some solutions of that problem?
Thank you in advacne!

Sudhakar Shinde on 14 Oct 2020
Edited: Sudhakar Shinde on 14 Oct 2020
%Try this:
Result = A(A<(0.8*S))
##### 2 CommentsShowHide 1 older comment
Sudhakar Shinde on 14 Oct 2020
Welcome. Glad to help

### More Answers (1)

Ameer Hamza on 14 Oct 2020
Edited: Ameer Hamza on 14 Oct 2020
A; % your matrix
S = max(A, [], 'all'); % same as: S=max(A(:))
S2 = max(A.*(A<0.8*S), [], 'all');
Fangjun Jiang on 14 Oct 2020
An easy counterexample:
%%
A=[1 -1]; % your matrix
S = max(A, [], 'all'); % same as: S=max(A(:))
S2 = max(A.*(A<0.8*S), [], 'all');
S1=max(A(A<0.8*S), [], 'all');
isequal(S1,S2)

R2019a

### Community Treasure Hunt

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

Start Hunting!