|
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <ibnvp3$b0c$1@fred.mathworks.com>...
> For duplicated elements issue, what about the below code? The idea is count the number of elements that match a unique representation of the first row, then clip it when this number is larger than the count for the first row.
>
> % Data
> A=ceil(4*rand(20,3))
>
> % Engine
> [m n] = size(A);
> u = unique(A(1,:)); % representation of first row
> [in J] = ismember(A,u);
> r = repmat((1:m)', n, 1);
> c = accumarray([r(in) J(in)],1); % count
> c = bsxfun(@min,c,c(1,:)); % clip
> rows = find(sum(c,2)==2);
>
> % Check
> rows
> A(1,:)
> A(rows,:)
>
> % Bruno
- - - - - - - - -
Very good, Bruno! That would handle the general case for any n. In effect you are getting a histogram of each row but with counts restricted to the values that occur in the first row. Then as you say, each histogram is "clipped" to the histogram of the first row itself. In each row that would give you the best match among possible one-to-one mappings.
One minor correction, though. The last line should read
rows = find(sum(c,2)>=2);
to be in accordance with the "at least" in the statement "at least two values in common".
Roger Stafford
|