How do I make a for loop and use logical operators
Show older comments
For my college class I have this problem Assign numMatches with the number of elements in userValues that equal matchValue. Ex: If matchValue = 2 and userVals = [2, 2, 1, 2], then numMatches = 3.
My code is
function numMatches = FindValues(userValues, matchValue)
arraySize = 4; % Number of elements in userValues array
numMatches = 0; % Number of elements that equal desired match value
for i = 1:arraySize
if (userValues ~= matchValue)
numMatches = arraySize - i
end
end
end
I also tried
If (userValues == matchValue)
but it did not work I tried with a input of FindValues([2, 2, 1, 2], 2) and it didn't work.
any recommendations
Accepted Answer
More Answers (0)
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!