Return 1 if number a exists in vector b otherwise return 0.
a = 3; b = [1,2,4];
Returns 0.
a = 3; b = [1,2,3];
Returns 1.
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.
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
While evaluating the solution, the server encountered an error caused by temporary unavailability of MATLAB Service. Wait a few minutes for the MATLAB Service to return, and then rescore.
function y = existsInVector(a,b)
y=ismember(a,b);
end
There is a pre-made function for this.
y = ismember(a,b)
Thanks! Have updated tests.
Find state names that start with the letter N
465 Solvers
221 Solvers
Cell Counting: How Many Draws?
254 Solvers
392 Solvers
Find the index of the largest value in any vector X=[4,3,4,5,9,12,0,4.....5]
229 Solvers