Using MATLAB I want to check 2 vectors, for example:
A = [1 2 3 4 5 6 7 8 9 10]
B = [10 9 8 7 6 11 12 13 14 15]
and write a matrix that checks each element B
if it is in A
, if it is not in A
, then append the element to A
. So in the end I should have a new matrix H=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]
. I want to check vector A
from the end. This is the code I have right now:
A=[1 2 3 4 5 6 7 8 9 10];
B=[10 9 8 7 6 11 12 13 14 15];
for i=A(end:-1:1)
for j=B(1:1:end)
if B(j)==A(i)
pass
else
C=B(j);
H=[A,C]; % i want to append the new values at the end of vector A
end
end
end
The error I get is in the if statement: if B(j)==A(i)
Index exceeds number of array elements.