Compute difference between rows

14 ビュー (過去 30 日間)
muhammad muda
muhammad muda 2019 年 2 月 25 日
コメント済み: Shen 2022 年 10 月 19 日
I have 4 x 3 matrix and the three columns represent age, height and weight. How do I calculate the magnitude of difference between each row; starting with set (row) 1 and 2, set 1 and 3, and set 1 and set 4. Then, I repeat the same to find the difference between set 2 and 3, and set 2 and set 4, up until set 3 and 4. The difference in this case is defined as summation of max(A(j), B(j)) - min (A(j), B(j)).

採用された回答

Jos (10584)
Jos (10584) 2019 年 2 月 25 日
I do not understand where A and B come from but this gives the differences between all combinations of 2 rows of the matrix M.
M = randi(100,4,3) % example data
r = nchoosek(1:size(M,1), 2)
D = M(r(:,1),:) - M(r(:,2),:)
  2 件のコメント
muhammad muda
muhammad muda 2019 年 2 月 25 日
wow, that's impressive! thanks!
Shen
Shen 2022 年 10 月 19 日
Nice Solution

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by