4

I have following string

'A, B, C, D'

from which I want to make a cell array such as

{ 'A', 'B', 'C', 'D' }

How would I be able to do this in Matlab?

3 Answers 3

5

Here's a solution that will cut up the string at commas, semicolons, or white spaces, and that will work for strings of any length

string = 'A, BB, C'

tmp = regexp(string,'([^ ,:]*)','tokens');
out = cat(2,tmp{:})


out = 

    'A'    'BB'    'C'
Sign up to request clarification or add additional context in comments.

Comments

3

For your specific example try:

cellstr(strread('A, B, C, D','%c,'))'

Comments

3

a more simple way: t1 = strsplit('A, B, C, D', ',');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.