Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating the maximum distance between elements of vector in MATLAB

Let's assume that we have a vector like

x = -1:0.05:1;
ids = randperm(length(x));
x = x(ids(1:20));

I would like to calculate the maximum distance between the elements of x in some idiomatic way. It would be easy to just iterate over all possible combinations of x's elements but I feel like there could be a way to do it with MATLAB's built-in functions in some crazy but idiomatic way.

like image 586
lhahne Avatar asked Jan 26 '26 20:01

lhahne


1 Answers

What about

max_dist = max(x) - min(x)

?

like image 174
midtiby Avatar answered Jan 29 '26 10:01

midtiby



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!