1

I hate asking this, but I am so close to figuring it out and it's really bothering me. I need to switch my strings into camelcase. I got rid of the spaces, I can uppercase the correct letters and I can remove the vowels, but I need to keep the very first letter of the code and I can't seem to be able to get it to stay. I've tried indexing it six different ways, to no avail.

function[cameltoe] = abbreviatingCamelCase(firstWord)
indexing = find(firstWord(1:end - 1) == ' ');%I want to find all the spaces here
firstWord( indexing + 1) = upper(firstWord(indexing + 1)); %I want to uppercase all the words     following a space
firstWord(firstWord == ' ') = [];
firstWord(ismember(firstWord, ' aeiou')) = [];
cameltoe = firstWord;

'one fish two fish red fish blue fish' should turn into 'onFshTwFshRdFshBlFsh'. I've been working on this for at least two hours. I tried indexing the firstWord inside where the ' aeiou' is, but that doesn't seem to work.

Jessica Marie
  • 293
  • 5
  • 16

1 Answers1

1

Hope you don't mind that I created an extra variable. Is this what you're looking for?

firstWord = 'one fish two fish red fish blue fish'
indexing = find(firstWord(1:end - 1) == ' ');%I want to find all the spaces here
firstWord( indexing + 1) = upper(firstWord(indexing + 1)); %I want to uppercase all the words     following a space
firstWord(firstWord == ' ') = [];
Li = ismember(firstWord, 'aeiou');
Li(find(Li,1,'first'))=0;
firstWord(Li) = [];
cameltoe = firstWord

Edit: if you want to keep the first letter, regardless of being a vowel:

indexing = find(firstWord(1:end - 1) == ' ');
firstWord( indexing + 1) = upper(firstWord(indexing + 1)); 
firstWord(firstWord == ' ') = [];
firstWord([false ismember(firstWord(2:end), 'aeiou')]) = [];
cameltoe = firstWord;
Wooly Jumper
  • 443
  • 2
  • 12
  • ....yes. I like love you for that. I tried to do that, but I guess I did something weird. It's been like the bane of my existence so this is like a huge relief. I'm just curious as to ow 'first' works. I was trying to straight index it. Except now it messes with my first test case :/ 'woot I love matlab' needs to be 'wtILvMtlb' and it has an o in it now – Jessica Marie Sep 19 '14 at 20:41
  • `'first'` is part of the `find` funcion: `find(,k,'first')` gives the `k` first elements that are true in the logical. – Wooly Jumper Sep 19 '14 at 20:43
  • In the question it says you want the first vowel? Do you only want the first letter? That makes life a lot easier – Wooly Jumper Sep 19 '14 at 20:44
  • I fixed it :) technically I want the first letter, especially if it's a vowel. I probably should have specified that a little better, but I figured it out :) I appreciate the help <3 – Jessica Marie Sep 19 '14 at 20:47
  • Yeah, none of them should be capitalized. The test cases run perfectly, which is what I'm concerned about it. – Jessica Marie Sep 19 '14 at 20:52
  • Sorry if I misunderstand; but do you realize there is a vowel in 'wtILvMtlb'? if you want to get rid of that 'I' write `Li = ismember(lower(firstword), 'aeiou')` – Wooly Jumper Sep 19 '14 at 20:57