You have not documented the purpose of the code, so we cannot know what the desired outcome is.
You use factor(). The Mathworks provided factor() returns something that is a vector unless the input is a prime. You then compare that likely vector to n. Remember that if VECTOR is considered true only if all the entries in the vector are non-zero. Your code therefore ends up testing that all of the factors of the number are <= 5. If that is your intent, then we recommand that you code
instead of people having to guess about whether you understood how if and while work with vectors.