matlab - Return Unique Element with a Tolerance -


in matlab, there unique command returns thew unique rows in array. handy command.

but problem can't assign tolerance it-- in double precision, have compare 2 elements within precision. there built-in command returns unique elements, within tolerance?

with r2015a, question has simple answer (see my other answer question details). releases prior r2015a, there such built-in (undocumented) function: _mergesimpts. safe guess @ composition of name "merge similar points".

the function called following syntax:

xmerged = builtin('_mergesimpts',x,tol,[type]) 

the data array x n-by-d, n number of points, , d number of dimensions. tolerances each dimension specified d-element row vector, tol. optional input argument type string ('first' (default) or 'average') indicating how merge similar elements.

the output xmerged m-by-d, m<=n. it sorted.

examples, 1d data:

>> x = [1; 1.1; 1.05];             % elements need not sorted >> builtin('_mergesimpts',x,eps)   % output sorted ans =     1.0000     1.0500     1.1000 

merge types:

>> builtin('_mergesimpts',x,0.1,'first') ans =     1.0000  % first of [1, 1.05] since abs(1 - 1.05) < 0.1     1.1000 >> builtin('_mergesimpts',x,0.1,'average') ans =     1.0250  % average of [1, 1.05]     1.1000 >> builtin('_mergesimpts',x,0.2,'average') ans =     1.0500  % average of [1, 1.1, 1.05] 

examples, 2d data:

>> x = [1 2; 1.06 2; 1.1 2; 1.1 2.03] x =     1.0000    2.0000     1.0600    2.0000     1.1000    2.0000     1.1000    2.0300 

all 2d points unique machine precision:

>> xmerged = builtin('_mergesimpts',x,[eps eps],'first') xmerged =     1.0000    2.0000     1.0600    2.0000     1.1000    2.0000     1.1000    2.0300 

merge based on second dimension tolerance:

>> xmerged = builtin('_mergesimpts',x,[eps 0.1],'first') xmerged =     1.0000    2.0000     1.0600    2.0000     1.1000    2.0000   % first of rows 3 , 4 >> xmerged = builtin('_mergesimpts',x,[eps 0.1],'average') xmerged =     1.0000    2.0000     1.0600    2.0000     1.1000    2.0150   % average of rows 3 , 4 

merge based on first dimension tolerance:

>> xmerged = builtin('_mergesimpts',x,[0.2 eps],'average') xmerged =     1.0533    2.0000   % average of rows 1 3     1.1000    2.0300 >> xmerged = builtin('_mergesimpts',x,[0.05 eps],'average') xmerged =     1.0000    2.0000     1.0800    2.0000   % average of rows 2 , 3     1.1000    2.0300   % row 4 not merged because of second dimension 

merge based on both dimensions:

>> xmerged = builtin('_mergesimpts',x,[0.05 .1],'average') xmerged =     1.0000    2.0000     1.0867    2.0100   % average of rows 2 4 

Comments

Popular posts from this blog

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - SSE Emitter : Manage timeouts and complete() -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -