All combinations of the sum of 2 columns

2 visualizzazioni (ultimi 30 giorni)
I am looking to combine each of these columns to find the greatest x. I need to check every combination of the two columns that are being subtracted from eachother. Im only ever going to be comparing 2 columns together at once. After x has a new matrix I'm going to pull max to continue. This is a simplified version of my code, I have many columns that I am pulling from excel to compare.
a = [29;31;34]
b = [31;31;31]
x = (b-a) % all possibilities for b-a

Risposta accettata

Torsten
Torsten il 2 Ott 2022
a = [29;31;34].' ;
b = [31;31;31] ;
x = b-a
x = 3×3
2 0 -3 2 0 -3 2 0 -3
xmax = max(x(:))
xmax = 2
  1 Commento
Walter Roberson
Walter Roberson il 2 Ott 2022
The max will be max(b)-min(a) or max(a)-min(b). If you use bounds() you can calculate these efficiently.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by