5

say I have an array of chars which looks like....

   hello
   hillo
   hello

and I would like to convert them to a cell array which would be the same as...

     A = {'hello';'hillo';'hello'}

how would I go about doing this, I've tried using mat2cell but it appears to just put everything into one large cell and doesn't really split them up.. So say for example with the original array of chars it would output like this if i put

     A = mat2cell(arrayofchars)

     [3x5 char]

    instead of the preferred output of...

     'hello'
     'hillo'
     'hello'

Sorry if I haven't explained my problem very well! Im quite new to matlab!

Cheers!

bdavies6086
  • 382
  • 1
  • 5
  • 19
  • 7
    Did you try `cellstr`? – Divakar Sep 01 '14 at 11:31
  • @RobertP. I am sure this is a duplicate case and don't want to burden `SO` with more of these. I won't fight if someone wants to go ahead and post this as an answer though :) – Divakar Sep 01 '14 at 14:47
  • @Divakar, I posted your answer as CW so that it won't appear unanswered. Hope that's OK with you =) (I agree that it's a duplicate, and that it somewhat clutters the site. But then again it hasn't been closed as a dupe yet, and having similar questions with different wording might help others find answers, thus avoiding even more duplicates...) – Stewie Griffin Sep 01 '14 at 18:32

1 Answers1

5

You can use the function cellstr to do this, as proposed by Divakar.

A = ['hello'
     'hillo'
     'hello']

C = cellstr(A)
C =     
    'hello'
    'hillo'
    'hello'
Community
  • 1
  • 1
Stewie Griffin
  • 14,889
  • 11
  • 39
  • 70