Info
This question is closed. Reopen it to edit or answer.
Identify integers in a matrix
1 view (last 30 days)
Show older comments
Task: Write a function sumDiv5 which receives one input argument and returns how many elements of the input variable are divisible by 5.
When I have a row vector I am able to calculate this, but when I input a matrix my answer does not display correctly, what is wrong with my code?
function output= sumDiv5 (numbers)
A= floor(rem(numbers,5));
count=sum(A==0);
output=count;
Example of what happens:
>> sumDiv5(4:9)
ans =
1
>> sumDiv5([0 1 2 3 4; 2 5 8 13 15])
ans =
1 1 0 0 1
>>
1 Comment
Answers (1)
Image Analyst
on 27 Sep 2015
You were told how to do this in your duplicate question: http://www.mathworks.com/matlabcentral/answers/245287#comment_312443
You didn't use (:) like you were told, so it's not doing it on the whole 2D matrix but on each column one column at a time.
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!