To create a mod
function without using the built-in mod
function in MATLAB, you can use the following code:
main.m195 chars7 lines
In this function, we first calculate the quotient using the fix
function. We then subtract quotient*b
from a
to get the modulus. We can call the myMod
function to calculate the modulus of two numbers as follows:
main.m38 chars5 lines
The value of modulus
in this case would be 1
, which is the expected result of 10 mod 3
.
gistlibby LogSnag