Tag Archives: String


Manipulating a string in MATLAB

Manipulating a string in MATLAB.

Following the previous post, where a string can be modified at vowel locations, and written over several times in a cyclic order, this post is about some more  vowel manipulation using Matlab.

So, after the previous post, my colleagues at work gave me a new challenge to do in Matlab. The problem statement was :Matlab is given a string (aka statement) which is a general combination of a lot of vowels and constants that make up words. Say for example like this:

monkeys like eating bananas that are ripe and yellow.

Assuming all the letters are in small ( program can be edited to have letter sin both caps and small as well) , the program reads through the statement and replace the last vowel in every word with nothing , or just truncates it. To add to the challenge the solution must be done without using an inbuilt library functionality.

Therefore after doing what has been asked for, the final output should be this :

monkys lik eatng banans tht ar rip nd yellw.

So,  attempted to solve this using matlab and you can find the code here:

Code here:

The way I solved is this. I am sure there can be several other ways to do that, and I am looking forward to hear from you in the comments section.

My algorithm:

  1. Add a space to the end of the string.
  2. Find the number of spacer by iterating through the string and checking for integer value of each character. The ASCII value of space is 32.
  3. The number of space is equal to the number of words then. Since we have added an extra space to the end.
  4. Now ask matlab to loop through each word. This can be done by space locations and first character. It can be made simpler by adding a space to the beginning of the statement as well. Then the whole string is homogeneously spaced.
  5. Fing the index of vowels in each word.
  6. list the index of each vowel
  7. Remove it by using a logical indexing operation.
  8. Print it.
  9. And you are done !

Download code here.

Let me know about your algorithm in the comment sections.







Writing Impositions in Matlab

Writing Impositions in Matlab

This post is for students who do not do their homework (like me when I was in school) and are punished with writing impositions. The imposition would usually be writing something like a very long statement with no meaning several times. Like back in my school days, when we were told to write them on paper using a pen or pencil. But these days students and truants are asked (ordered!) to write them in a word-processing software. Well, we can think of using the classic trick of Ctrl+C and Ctrl+V, but it depends on the imposition type, right!

Like for say here, we are asked to write this statement :

“The quick brown fox jumps over the lazy dog”.

And the teacher asks you to change every vowel with its preceding vowel in each iteration.That would mean , in my first statement, a is replaced to e, e is replaced by i, i is replaced by o, o is replaced by u, and u is replaced by a. In subsequent iterations, the replaced vowels are replaced by their preceding vowel. And this has to be done say 100 times. (Quite a tough punishment!). This case can not be done in MS Word or any other word processor, so the student has to do type this manually each time or just do his homework instead.

However, good news! I have a Matlab code for you, which will do it for you however number of times you want to write. In the end, all you have to do copy the final output to a word processor  and get the print. The code is as simple it can be without using any library functions so that people with no knowledge about Matlab can still use, because then it is just English to understand.

You can get the code here, and use an online compiler to run it .

Download code here: