Find maximum difference between two arrays
24 ビュー (過去 30 日間)
古いコメントを表示
I have to arrays of the same size 1x101, how can I find the absolute maximum difference between the arrays?
This is what I tried but it is giving me the incorrect answer:
[m] = max( abs( A(1,101) - B(1,101) ))
1 件のコメント
Dyuman Joshi
2023 年 10 月 6 日
編集済み: Dyuman Joshi
2023 年 10 月 21 日
Because the code compares a single element i.e. (1,101), not the whole vectors.
Use this -
m = max(abs(A-B.'),[],'all');
For more information, refer to - Compatible Array Sizes for Basic Operations
回答 (1 件)
Bruno Luong
2023 年 10 月 6 日
編集済み: Bruno Luong
2023 年 10 月 6 日
No need to compare all the pairs
A = randn(1,101);
B = randn(1,101);
dmaxBruteForce = max(abs(A-B.'),[],'all')
dmaxSmart = max(abs([max(B)-min(A), max(A)-min(B)]))
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Operators and Elementary Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!