In: Advanced Math
MATLAB CODE
%making the function myfn6 with arguments vector u and
value a
%returns logical vector w
function w=myfn6(u,a)
%looping through the elements in u
for i=1:length(u)
%if the element is found w at that index is made
true else it is false
if(u(i)==a)
w(i)=true;
else
w(i)=false;
end
end
%just to check if w is logical
%t=islogical(w)
end
OUTPUT
w is a logical array it can be represented in 0 and 1 only, where 0 is false and 1 is true
MATLAB CODE TO CHECK ALL ELEMENTS IN U AT THE SAME TIME
%making the function all_element_in with arguments vector u and
vector a
%returns logical vector w
function w=all_element_in(u,a)
%looping through the elements in u
for i=1:length(u)
%looping through the elements in a
for j=1:length(a)
%if the element is found
w at that index is made true else it is false
if(u(i)==a(j))
w(i)=true;
%breaking from loop
break
else
w(i)=false;
end
end
end
%t=islogical(w)
end
OUTPUT
checks if any one element in a is in u
Please note save the code with the same name as the function