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

1 view (last 30 days)
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!

Accepted Answer

Image Analyst
Image Analyst on 10 Jan 2015
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);

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!