|
"ade77 " <ade100a@gmail.com> wrote in message <hdk2vr$i5k$1@fred.mathworks.com>...
> Hi
>
>
> I am trying to manipulate a large vector without a loop.
>
> For example
> a = [1:10], b = [1 2 4 5 8 10]
>
> a b
>
> 1 1
> 2 2
> 3 4
> 4 5
> 5 8
> 6 10
> 7
> 8
> 9
> 10
>
> I want all the elements of 'a' to be in in 'b'. At the end I want 'b' to be b= 1:10
>
> 1. both vectors are already sorted
> 2. any element of 'a' not in 'b', should be added to b, and the index noted.
> 3. for the example above, first index of 'a' is 1, it is in 'b',next, second index of 'a' is 2, it is in 'b'.
> 4.third index of 'a' is 3, not in 'b', hence 3 will be added to b, and the index noted (3).
> 5. Note now, that b is now [1 2 3 4 5 8 10].
> 6 Next,'a' at index 4 is 4, which is also in index 4 of b, then continue to index 5 of 'a' e t c.
>
> at the end b = [1:10], index = 3,6,7,9.
>
>
Actually not that tricky.
a=[1:10];
b = [1 2 4 5 8 10];
NewVec=sort(unique([a b]) );
IndexVec=find(~ismember(NewVec, b) );
Regards Matt
|