フィルターのクリア

What is an efficient way of finding the maximum value under a certain limit?

2 ビュー (過去 30 日間)
Ali Almakhmari
Ali Almakhmari 2022 年 7 月 23 日
回答済み: Torsten 2022 年 7 月 23 日
Can you guys throw few lines my way that will help me find the maximum value under a certain threshold in a matrix? Lets say I have this matrix: [1,2,3;4,5,6;7,8,9] and I would like to find the maximum value below 8, so the code will return the index and the value, which in this case will be the number 7. The reason I emphasized efficiency is because I will be running this so many times in a bunch of for loops, so I was looking for the fastest thing. Thanks in advance.

採用された回答

Torsten
Torsten 2022 年 7 月 23 日
A = [1,2,3;4,5,6;7,8,9];
A(A>=8) = -Inf
A = 3×3
1 2 3 4 5 6 7 -Inf -Inf
[m,i] = max(A,[],'All')
m = 7
i = 3
[row,col] = ind2sub(size(A),i)
row = 3
col = 1

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProblem-Based Optimization Setup についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by