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

조회 수: 4 (최근 30일)
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
Sudhakar Shinde 2020년 10월 14일
편집: Sudhakar Shinde 2020년 10월 14일
%Try this:
Result = A(A<(0.8*S))

추가 답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 10월 14일
편집: Ameer Hamza 2020년 10월 14일
A; % your matrix
S = max(A, [], 'all'); % same as: S=max(A(:))
S2 = max(A.*(A<0.8*S), [], 'all');
  댓글 수: 3
Ameer Hamza
Ameer Hamza 2020년 10월 14일
No, both will be equivalent, even if matrix have negative values. Infact, using multiplication is much faster
A = randn(10000); % both positive and negative values
S = max(A, [], 'all');
tic
S21 = max(A.*(A<0.8*S), [], 'all');
t1 = toc;
tic
S22 = max(A(A<0.8*S), [], 'all');
t2 = toc;
tf = isequal(S21, S22);
Result
>> t1
t1 =
0.3251
>> t2
t2 =
1.2465
>> tf
tf =
logical
1
Fangjun Jiang
Fangjun Jiang 2020년 10월 14일
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)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by