matlab - Find the minimum difference between any pair of elements between two vectors -
which of following statements find minimum difference between pair of elements (a,b) vector , b vector b.
a. [x,y] = meshgrid(a,b); min(abs(x-y)) b. [x,y] = meshgrid(a,b); min(abs(min(y-x))) c. min(abs(a-b)) d. [x,y] = meshgrid(a,b); min(min(abs(x-y)))
can please explain me?
by saying "minimum difference between pair of elements(a,b)", presume mean treating , b sets , intend find absolute difference in any possible pair of elements these 2 sets. in case should use option d
[x,y] = meshgrid(a,b); min(min(abs(x-y)))
explanation: meshgrid turns pair of 1-d vectors 2-d grids. link can explain mean say:
http://www.mathworks.com/help/matlab/ref/meshgrid.html?s_tid=gn_loc_drop
hence (x-y) give difference in possible pairs (a,b) such belongs , b belongs b. note 2-d matrix.
abs(x-y) return absolute values of elements in matrix (the absolute difference in each pair).
to find smallest element in matrix have use min(min(abs(x-y))). because if z matrix, min(z) treats columns of z vectors, returning row vector containing minimum element each column. single min command give row vector each element being min of elements of column. using min second time returns min of row vector. smallest element in entire matrix.
this can help:
http://www.mathworks.com/help/matlab/ref/min.html?searchhighlight=min
options c correct if treat , b vectors , not sets. in case won't considering possible pairs. you'll end finding minimum of (a-b) a,b both in same position in corresponding vectors (pair-wise difference).
Comments
Post a Comment