matlab cody study notes day10

(1)Check if number exists in vector
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. This
question is still very simple. At first glance, I think the find function is used, but it still needs to be judged.
Answer:
if true(find(b == a))
y = 1
else
y = 0
end
Answer:
y = ~isempty(b(b == a))
or simpler:
Answer:
y = ismember(a,b )

(2)Remove the vowels
Remove all the vowels in the given phrase.
Example:
Input s1 ='Jack and Jill went up the hill'
Output s2 is'Jck nd Jll wnt p th hll'
because vowels are not often used, so this Road Title look a little rusty, and in fact digital almost, that is a selection determination:
a:
S2 = [];
S3 = 'aAeEiIoOuU';
L = strlength (S1);
Ll = strlength (S3);
In Flag = 0;
J = 1;
for i=1:L
for k=1:L1
if s1(i)s3(k)
flag=1;
continue;
end
end
if flag
0
s2(j)=s1(i);
j=j+1;
end
flag=0;
end
end
Note the difference between strlength and length.
The other topics are very simple.

Guess you like

Origin blog.csdn.net/yxnooo1/article/details/113898413