picking maximum difference across entries of row vectors

1 次查看(过去 30 天)
I have a matrix A. I would like to create a column vector B that is
for each row, take a difference between every possible pair of two elements in the row and returns the maximum difference
For example, if A= [1 3 6 7 10], then B=[9]. Please advise a compact way to drive B.

采纳的回答

Paolo
Paolo 2018-6-6
编辑:Paolo 2018-6-6
Perhaps a simpler solution which only requires a sort:
A = [1 3 6 7 10];
A = sort(A);
B = A(end) - A(1);
B =
9
Example 1:
A= [6 3 324 2 123];
A = sort(A);
B = A(end) - A(1);
B =
322
Example 2:
A = [111 34 88 11 12];
A = sort(A);
B = A(end) - A(1);
B =
100

更多回答(0 个)

类别

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

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by