Str to Cell (trivial ?)

Hallo there,
I would like to make out of a big string a cell array, e.g.
str1 = ['aa1','bb1','cc1'];
str2 = ['aa2','bb2','cc2'];
Edit : what I mean is a string representing various rows and columns, i.e. strMatrix = [str1 ; str2 ; strN]], which has to be converted into a cell matrix.
The question is how to make out of each comma separated string entry, seperate cell array entry. Im looking for something similar like
dataCell = {eval(str1),';', ...
eval(str2)};
At the end I want to have the following :
dataCell = {'aa1','bb2','cc2'; 'aa2','bb2','cc2'}
Thanks in advance.

댓글 수: 6

C.J. Harris
C.J. Harris 2012년 1월 11일
Your main problem is that once you create the strings 'str1' and 'str2' there is no way of knowing that they were originally three seperate strings, hence splitting them again becomes troublesome.
RubenMath
RubenMath 2012년 1월 11일
So, the only solution is
dataCell {end+1} = 'aa1';
?1?
Daniel Shub
Daniel Shub 2012년 1월 11일
What are you trying to do? Are aa1, bb1, always three characters? What is the original input that you have?
RubenMath
RubenMath 2012년 1월 11일
Im trying to find a performative solution for creating a cell array out of a string array.
Jan
Jan 2012년 1월 11일
@RubenMath: Please consider this:
['aa1', 'bb1', 'cc1'] is identical to 'aa1bb1cc1'
So your inputs are not clear yet.
RubenMath
RubenMath 2012년 1월 12일
what I mean is a string representing various rows and columns, i.e. strMatrix = [str1 ; str2 ; strN], which has to be converted into a cell matrix.

댓글을 달려면 로그인하십시오.

답변 (1개)

Daniel Shub
Daniel Shub 2012년 1월 11일

0 개 추천

What about
str1 = {'aa1','bb1','cc1'};
str2 = {'aa2','bb2','cc2'};
dataCell = [str1; str2];

댓글 수: 3

Titus Edelhofer
Titus Edelhofer 2012년 1월 11일
If the str1 and str2 are already given as cell arrays you might just write
dataCell=[str1; str2];
But I guess the main question is still: how do the original strings look like? str1 in the original question is just 'aa1bb1cc1'.
Titus
Jan
Jan 2012년 1월 11일
@Daniel: {str1{:};str2{:}} is less efficient than [str1; str2].
Daniel Shub
Daniel Shub 2012년 1월 12일
Of course it is. Thanks guys. I edited the answer.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2012년 1월 11일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by