Find maximum among the elements in the matrix lower than 80% of max element of entire matrix
2 ビュー (過去 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!
0 件のコメント
採用された回答
Sudhakar Shinde
2020 年 10 月 14 日
編集済み: Sudhakar Shinde
2020 年 10 月 14 日
%Try this:
Result = A(A<(0.8*S))
2 件のコメント
その他の回答 (1 件)
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
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
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 Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!