|
Hi Ann,
it took me a while to figure it out and I am sure, there are better solutions. So hope this works for you...
n = max(max(a),max(b));
e = accumarray(a,ones(size(a)),[n 1]) - accumarray(b,ones(size(b)),[n 1]);
g = [1:n]';
f = g(find(e));
e = e(f);
ix = cellfun(@(x,y) repmat(x,y,1),num2cell(f),num2cell(e),'uniformoutput',false);
ix = cell2mat(ix)
ix =
1
1
4
6
HTH
Wolfgang
"ann au" <fannylyy@hkusua.hku.hk> wrote in message <geit0p$716$1@fred.mathworks.com>...
> Hi,
>
> I have 2 vectors:
> a=[1 1 1 1 1 2 2 3 4 5 6 7]'
> b = [1 1 1 2 2 3 5 7]'
>
> I want to get the following result:
> a=[ 1 1 4 6 ]'
>
> What code should i use? Thanks!
>
> Ann
|