Calculate differences between all values elements in a vector and increase max diff by one

I'm trying to produce a code that will calculate the differences between all values in a vector.
The Vectors could also be random*.
Specifically, say I have a vector A [2 3 1 4] and a Vector B [4 4 2 4].
My Vector C should show the difference betweeen the Values of A and B, so C should be [2 1 1 0].
The max difference is 2, and it can easily be found with max(C).
What I want to do is that it should increase the Value of the element of A by one that was linked to the highest difference.
Any help would be appreciated.

 採用された回答

KSSV
KSSV 2021 年 6 月 10 日
A = [2 3 1 4] ; B =[4 4 2 4];
AB = B-A ;
[val,idx] = max(AB) ;
A(idx) = A(idx)+1

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

製品

リリース

R2018b

タグ

質問済み:

2021 年 6 月 10 日

コメント済み:

2021 年 6 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by