Split the given string into characters
Show older comments
I have a column in my table that has values such as '2.6ELKUxQKWPVJVHxxxxC.4xxxIxSxJJxxxxx', it has altogether 37 single characters. I want to split the string into 37 different columns for further data analysis. I have tried using 'split' function, but it doesn't work.
1 Comment
"I want to split the string into 37 different columns..."
Your char vector already has 37 columns. This is easy to check:
>> str = '2.6ELKUxQKWPVJVHxxxxC.4xxxIxSxJJxxxxx';
>> size(str)
ans =
1 37
Accepted Answer
More Answers (2)
KSSV
on 17 May 2018
str = '2.6ELKUxQKWPVJVHxxxxC.4xxxIxSxJJxxxxx' ;
iwant = cell(1,length(str)) ;
for i = 1:length(str)
iwant{i} = str(i) ;
end
3 Comments
Much simpler to use num2cell:
iwant = num2cell(str);
Guillaume
on 17 May 2018
And even much simpler is not to bother at all. str already has 37 different columns. Each one can be accessed with str(columnindex).
Guillaume
on 17 May 2018
A char array such as
str = '2.6ELKUxQKWPVJVHxxxxC.4xxxIxSxJJxxxxx'
already has different columns. If you want to access column 6 of str, it's simply:
str(6)
Exactly the same as when accessing columns of a numerical matrix.
1 Comment
Image Analyst
on 17 May 2018
He means columns of his table, not columns of that string.
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!