Problem 838. Check if number exists in vector
Solution Stats
Problem Comments
-
7 Comments
Show
4 older comments
Richard Zapor
on 17 Jul 2012
Add test vector a = -12;
b = [1,3,4,5,6,7,8,-12,2]; and rescore.
Better is add a=-randi(16); b= [1 2 3 a];
These will eliminate answers like #6.
frank mcnally
on 15 Aug 2019
Tests allow incorrect solution to pass:
function y = existsInVector(a,b)
y=0
for i = 1:numel(b);
if i==a
y=1
break
end
end
end
Jyothsna Chintala
on 21 Apr 2020
good
Nicholas Bitler
on 26 Nov 2020
that was fun, took me a couple minutes
Qingyin Zhang
on 29 Nov 2020
y = sum(b == a);
Colin McNicholas
on 13 Dec 2021
Not too bad
Hung Van Le
on 24 Feb 2022
yay
Solution Comments
Show commentsProblem Recent Solvers9297
Suggested Problems
-
Maximum running product for a string of numbers
1898 Solvers
-
Renaming a field in a structure array
1319 Solvers
-
4173 Solvers
-
Find out sum and carry of Binary adder
1079 Solvers
-
416 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!