Find the m-th smallest number in Matlab? -
this question has answer here:
is there efficient way find m-th smallest number in vector of length n in matlab? have use sort() function? , regards!
edit 2: eitan pointed first part of answer doesn't address question of finding smallest m-th value regarding m-th element after min value. rest of answer remains... +1 eitan's sharpness. while sort
efficient begin with, can try see whether find
better. example:
id=find(x>min(x),m,'first'); id(end) % index of smallest m-th element in x
the function find
has added functionality lets find 'first' or 'last' elements meet criterion. example, if want find first n
elements in array x
less value y
, use find(x<y,n,'first')
this operation stops first element meeting condition encountered, can result in significant time savings if array large , value find happens far end.
i'd recap @woodchips said in this discussion relevant question:
the best way speed basic built-in algorithms such sort faster hardware. speed else too. matlab doing in efficient manner, using optimized code internally. saying this, maybe gpu add-on can improve too...
edit: it's worth, adding muster's comment, there fex file called nth_element mex wrap of c++ solution in o(n)
time need. (similar @ddd pointed to)
Comments
Post a Comment