How to convert comma separated string to array of row cells in matlab

I have a line

'A, B, C, D'

from which I want to create an array of cells, for example

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

How can I do this in matlab?

+4
source share
3 answers

Here's a solution that will cut the line with commas, semicolons or spaces, and will work for strings of any length

string = 'A, BB, C' tmp = regexp(string,'([^ ,:]*)','tokens'); out = cat(2,tmp{:}) out = 'A' 'BB' 'C' 
+5
source

In your specific example, try:

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

simpler way: t1 = strsplit ('A, B, C, D', ',');

+2
source

Source: https://habr.com/ru/post/1411793/


All Articles