Find maximum difference between two arrays
조회 수: 29 (최근 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에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!