Starting from:

$29

Homework 7 Iteration Practice

Function Name: countNum
Inputs:
1. (double) An array of any size MxN
2. (double) A particular number to search for
Outputs:
1. (double) A count of how many times the given number occurs in the array
Function Description:
Write a function in MATLAB named countNum() that will take in an input array of size
MxN and compare each index within the array to find if it is equal to the second input. The
output value should be equal to the number of indices in the array that are equal to the second
input.
Notes:
● The first input will always be a rectangular array of numbers. The second input will
always be a single number.
● You MUST use iteration on this problem.
*You have learned how to code something like this using logical masking, however, this should
be a simple function to learn the process of iteration.
Hints:
● Using a counter variable could be useful.

More products