Hello everybody,
Given 2 numbers p and q and a vector v, the question is, are BOTH elements in v?
by defining a function with both numbers p,q and vector v as input and the answer to above question being (either yes or no), the only allowed matlab routine is 'length' and only one loop can be used. the function needs to be tested.
this is what i had;
function [logica] = find(p,q,v)
for k = 1:length(v)
if v(k)==p || v(k)==q
logic = yes
else
logic = No
end
end
but this will only show either p or q is present and not both of them are present
Thanks.
1 Comment
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/469535-find-if-two-numbers-are-both-present-in-an-array#comment_719834
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/469535-find-if-two-numbers-are-both-present-in-an-array#comment_719834
Sign in to comment.