All combinations of the sum of 2 columns

2 次查看(过去 30 天)
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

采纳的回答

Torsten
Torsten 2022-10-2
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 个评论
Walter Roberson
Walter Roberson 2022-10-2
The max will be max(b)-min(a) or max(a)-min(b). If you use bounds() you can calculate these efficiently.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by