MATLAB: Excluded Digits from vector

matchstring

vector=[1 2 5 13 55 23 15],excluded dig=5 then out=[1 2 13 23] ,another example vector=[3 24 7 9 18 55 67 71],excluded dig=7 then out=[3 24 9 18 55]

Best Answer

  • I expect there is a much cleaner method, but here is one that works:
    vector = [1 2 5 13 55 23 15];
    exDigit = 5;
    v = vector;
    hasDigit = false(1,numel(v));
    while max(v>=1)
    hasDigit = hasDigit | mod(v,10)==exDigit;
    v = floor(v/10);
    end
    new_vector = vector(not(hasDigit))