How to test for integers and delete integers that do not perform to the test
Mostrar comentarios más antiguos
My assignment: Write a function sumDiv5 which receives one input argument and returns how many elements of the input variable are divisible by 5. You are not allowed to use FOR loops (we will study them next week)
My thinking is to divide the whole input by 5. Then to delete all the non-integer numbers (those not divisible by 5). How do I delete only the non-integer numbers instead of the whole matrix? (which is what my code does)
function output= sumDiv5 (input)
A=input/5;
if isreal(A) && rem(A,1)==0
else
A=[];
end
output=A;
Respuesta aceptada
Más respuestas (1)
James Tursa
el 27 de Sept. de 2015
1 voto
Hint: Take a look at the result of rem(A,1)==0. What do you get if you sum this up?
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!