0

I have a little problem. I know how to avoid it, but I'm not sure is the best.

String = textscan('Hello_World','%s','delimiter','_')

This returns a {1x1 cell} with a {2x1 cell} in it:

String =
{2x1 cell}

What I want requires an additional command:

String = String{1}

which yields what I want:

String = 
'Hello'
'World'   

I would be glad if anybody has a good tip.

horchler
  • 18,384
  • 4
  • 37
  • 73
Mar Vino
  • 17
  • 4
  • 1
    This is the documented behavior. From [the documentation](http://www.mathworks.com/help/matlab/ref/textscan.html#zmw57dd0e761624): `For each string conversion specifier in formatSpec, the textscan function returns a K-by-1 cell vector of strings, where K is the number of times that textscan finds a field matching the specifier.` You can remove a level of nesting using `String = [String{:}];` – sco1 Jan 05 '16 at 18:42
  • Other alternatives (`regexp`, `strsplit`, etc.) could potentially work 'better', but it depends on your actual application. – sco1 Jan 05 '16 at 18:54
  • You are right strsplit is the better alternative for my problem, thanks. – Mar Vino Jan 05 '16 at 23:19

0 Answers0