You can use a for
loop with an if
statement to accomplish this task. Here's the code below:
main.m349 chars11 lines
Output:
main.m17 chars2 lines
You can see that the new row vector only contains elements that are divisible by 3.
This code uses the mod()
function to check if an element is divisible by 3. The mod()
function returns the remainder when dividing the first argument by the second argument. So, if the remainder is 0, then the first argument is divisible by the second argument.
gistlibby LogSnag