Problem 22. Remove the vowels
Solution Stats
Problem Comments
-
10 Comments
What about y in the second test?
Why isn't y a vowel in english? In swedish we have nine vowels and y is one of them.
There is only five vowels in English.That is 'a,e,i,o,u'.
I don't understand why the following doesn't work:
expression = '[aeiouAEIOU]';
[~,noMatch] = regexp(s1,expression,'match','split');
[~,c] = size(noMatch);
cell_s2 = '';
for i = 1:c
cell_s2 = strcat(cell_s2,noMatch(i));
end
s2 = string(cell_s2);
nice
#WARNING
Character Array And String are not similar.
length('abc')
% 3
length("abc")
% 1
so 'abc' is NOT EQUAL to "abc"
use "char" function to get character array from string
char("abc")
% 'abc'
using
if ~any(s1(i) == 'aeiouAEIOU')
makes it real easy
The letters 'w' and 'y' are actually vowels.
(Perhaps not in Cody, perhaps not even in American English - I am not sure - but for certain they are in English...)
Regexp Regexp
Only 2 line of code thank for Regexp
Solution Comments
-
1 Comment
ismember aha
-
1 Comment
function s2 = refcn(s1)
s2 = [];
s3='aAeEiIoOuU';
L=strlength(s1);
L1=strlength(s3);
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
-
1 Comment
why no accept
-
1 Comment
I can't make this work on my PC (Matlab 2016 doesn't support double quotes and string arrays)
-
2 Comments
s1 = 'I don''t want to work. I just want to bang on the drum all day.';
How it is possible to read the string to the s1 including another quote at don''t
including lower() helped me with the capital I
-
1 Comment
'Y' is being considered as a consonant!
-
3 Comments
In addition to vowels, the second test also removes a space. While it's natural to want to clean up extra spaces, spaces are _not_ vowels.
The display of the test suite show the second space at the "I" being removed, but the actual test does not remove it. This is very confusing, but the test actually works as you would expect. It is just that the displayed "correct" answer is - in fact - not correct as you noted.
I had trouble with this as I saw your answer and accommodated their "error" in my solution. Except their error was only a display error and not an actual error in the test suite. Doh!
See https://www.mathworks.com/matlabcentral/cody/problems/22-remove-the-vowels/solutions/1218453 for a repaired version of your solution.
Of course I just noted that your solution is five months old, so you certainly won't care by now. C'est la vie.
-
1 Comment
Also should include other capitals
-
3 Comments
Anyone can see why this is not working? Works fine on my side.
Consider letter 'y'. It can be consonant or vowel, depend on context. More: http://en.wikipedia.org/wiki/Consonant#Letters
Initially I tried both ways with same results. My mistake was forgetting about the capital vowels. Thanks for the reply Jan.
-
1 Comment
very good solution!
-
1 Comment
can any one say what is the problem if we approch through ascii representation?
-
1 Comment
excellent example!
one "'" can make a very different situation between "regexp" and "regexpi".
-
1 Comment
For the second test-case, something is wrong.
* If you use the string that is given in S1 in MATLAB, you do NOT get the output that is listed.
* However, to get the output that is listed as the correct one, you cannot have the input that is given.
-
1 Comment
Regexp is apparently unable to detect the 'y' at the end of 'day'. This does not happen on my own computer. Very strange indeed.
-
1 Comment
Smaller but less explicit than 'ignorecase'. Anyway, good solution.
-
1 Comment
On my pc it works. Why not here?
-
2 Comments
Wait... how is this:
s2 = regexprep(s1,'[aeiouAEIOU]','');
shorter than this?
s2 = s1(regexpi(s1,'[^aeiou]'));
@Tom
I believe it is because the regexpi would be the same as including the 'ignorecase' option from regexprep command (including that makes the size 15).
-
2 Comments
Does it really matter if y is a vowel or not? XD
y or y not!!
thats the problem...
Problem Recent Solvers5624
Suggested Problems
-
2815 Solvers
-
374 Solvers
-
523 Solvers
-
928 Solvers
-
3596 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!