MATLAB: How do i determine the missing number in a vector where the numbers are in a set range

findvectors

Hello all! My problem is thus: If i have a set range of numbers, such as 1:20 and i have a given vector wherein merely 1 number from the given range is missing, instead replaced with a 0, how do i determine which number in the given range is missing? I realise this is probably a very simple problem, but i am a complete beginner i fear. Thank you in advance for your help!

Best Answer

If there are no other indexes that have a value of 0, you can simply do
missingIndex = find(m==0);
If there are other indexes that may have value 0 but not be "missing" then you need some reference array to compare against:
missingIndex = find(m~=mReference);