lisandrojim
lisandrojim

Reputation: 509

char to cell MATLAB

If I have this element type "char":

A=['abc';'dei';'fgh'];

And I want to obtain something like:

B=somefuntion(A)

And obtain something like this:

B={'abs';'dei';'fgh'}

I tried this function called char2cell, but the result was this:

B = 'adfbegcih';

I really appreciate any help, thanks!

Upvotes: 0

Views: 309

Answers (1)

Daniel
Daniel

Reputation: 36710

You can use mat2cell:

 F=mat2cell(A,ones(size(A,1),1),size(A,2))

The code splits every row into one cell(ones(size(A,1),1)) and keeps the columns together (size(A,2))

Upvotes: 2

Related Questions