Filter löschen
Filter löschen

Find maximum difference between two arrays

24 Ansichten (letzte 30 Tage)
Joe Cousins
Joe Cousins am 6 Okt. 2023
Bearbeitet: Dyuman Joshi am 21 Okt. 2023
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 Kommentar
Dyuman Joshi
Dyuman Joshi am 6 Okt. 2023
Bearbeitet: Dyuman Joshi am 21 Okt. 2023
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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Bruno Luong
Bruno Luong am 6 Okt. 2023
Bearbeitet: Bruno Luong am 6 Okt. 2023
No need to compare all the pairs
A = randn(1,101);
B = randn(1,101);
dmaxBruteForce = max(abs(A-B.'),[],'all')
dmaxBruteForce = 5.1894
dmaxSmart = max(abs([max(B)-min(A), max(A)-min(B)]))
dmaxSmart = 5.1894

Kategorien

Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by