string - MATLAB: how to split cell arrays of different delimiter numbers? -


assume there input cell:

input=

"82.3 4.3 john"

"4.2 0.0001 tim taylor"

this 2by1 cell array. need split 2by3 array like:

"82.3" "4.3" "john"

"4.2" "0.0001" "tim taylor"

the split(input) or split(input,'\t') returns error each row of cell includes different number of delimiters.

you can use split, differ depending on whether have cell array containing character vectors or cell array containing strings (i know, it's very confusing):

if input displayed this:

input =    2×1 cell array      '82.3   4.3 john'     '4.2    0.0001  tim taylor' 

then have cell array of character vectors, , can split @ tabs this:

str = split(input, char(9))  str =     2×3 string array      "82.3"    "4.3"       "john"           "4.2"     "0.0001"    "tim taylor" 


if input instead displayed this:

input =    2×1 cell array      ["82.3  4.3 john"      ]     ["4.2   0.0001  tim taylor"] 

then have cell array of strings, , need concatenate cells 2-by-1 array of strings before splitting @ tabs:

str = split([input{:}].', char(9))  str =     2×3 string array      "82.3"    "4.3"       "john"           "4.2"     "0.0001"    "tim taylor" 


note had use char(9) specify ascii tab character, , output in each case 2-by-3 array of strings.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -