Monday, August 20, 2007

Insert a quotation mark into a string in MATLAB

Another expression of inserting a quotation mark in a string is inserting a quotation mark in quotation marks. There are two solutions as far as I know.

  1. A recommended solution is using char(39) to generate the quotation mark. Char is a MATLAB function. This approach makes it much easy to read in eval function.
  2. There is another solution you can find in the Internet: using two quotation marks (without space between these two quotation marks) in a pair of quotation marks (this pair of quotation marks are used to indicate string) . It is possible to get lost with this approach if there are lots of quotation marks.
There is an example. Suppose we want to get a string here 'is' a dog.
  1.  a =['here ' char(39) 'is' char(39) ' a dog']
  2.  a ='here ''is'' a dog'


  1. this is great

  2. That was of great help! Thanks so much!

  3. Just what I was looking for!
    Greetings from Germany!

  4. It was very helpful.
    Thanks from United States

  5. Thanks from LA too!
    hey this is the greatest coolest tip ever :-p

  6. Dude, this is awesome, works great in regexp!