MATLAB: How to make a function that checks the divisibility of a given number, n, by 3, 5, 7, and 11.

divisibilityrem

I am trying to write a function div – divisibility(n) that checks the divisibility of a given number input n, by 3, 5, 7, and 11 for a hw problem. The problem requires that my output be a logical vector output of 4 elements corresponding to the divisibility by 3, 5, 7 and 11, respectively. For example, the output of divisibility(14) would be [0 0 1 0]. I have figured out how to write a function that gives a single output, but I do not know how to write a function that outputs a logical vector.
All I have so far is:
function div = divisibility(a)
div = rem(a,3)
end

Best Answer

This works:
divisibility = @(x) rem(x, [3 5 7 11]) == 0;
div = divisibility(14)
producing:
div =
0 0 1 0