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 Solvers9592
Suggested Problems
-
22943 Solvers
-
Arrange Vector in descending order
9311 Solvers
-
Convert a numerical matrix into a cell array of strings
1406 Solvers
-
Basics: 'Find the eigenvalues of given matrix
397 Solvers
-
496 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!