Given a collection of points, return the indices of the rows that contain the two points most distant from one another. The input vector p has two columns corresponding to the x and y coordinates of each point. Return ix, the (sorted) pair of indices pointing to the remotest rows. There will always be one unique such pair of points.
So if
p = [0 0] [1 0] [2 2] [0 1]
Then
ix = [1 3]
That is, the two points p(1,:) and p(3,:) are farthest apart.
More easy that it seems.
You need to specify "Euclidean" distance :-)
Good problem, not too hard but required thinking
no function squareform either... pffff
Why is there "undefined function 'dist' for input arguments of type 'double'."? Works on my machine (and online matlab too)
I solved the problem by an tedious approach.
remove ' diff ',but adds size -_-
:)))))
I am using matlab2010 but dist function is not available in it. Can you tell me how and where can I use this?
Without dist, but with str2num
I think it works w/ just x*[1;i] . No need to convert from a string.
i'm not sure this can always get the right answer,
so i need more debugging.
what is 'i'? This is strange but works.
@Claudia, "i" is the imaginary number sqrt(-1). Unless you overwrite it, it's always available to you in MATLAB without needing to declare it.
Excuse me?
This solution works fine, but requires the stats toolbox to function!
I dont get whay sort(unique(ix)) will give you the location of the two points. it is wrong for these points (0.9631 0.5468),(0.5211 0.2316),(0.4889,0.6241),(0.6791 0.3955),(0.3670 0.9890),
sort(unique(ix)) will return [1 2 5].
I think this solution is not right
I agree.
there may be something out of word,
if i put:
p =[1 0; 0 1;0 0; 1/sqrt(2) 1/sqrt(2) ]
your command would not right,
but 'unique' is very admirable.
This is the smallest solution not to use "dist," which is not in core Matlab. Nicely done!
I don't know why Cody allows answers which depend on toolboxes. The whole point should be to write one's own "distance" function.
Hard to believe you let 'dist' in but not 'pdist'.
pdist is not allowed!
I find this a little bit unfair: dist is a neural network toolbox function. It is not available in MATLAB core, and the problem does not specify this toolbox is needed.
Shame on me...