String problem

I want to store some strings in a row matrix. so used like this
>> str=['RR' 'DET' 'LMAX' 'ENT' 'LAM' 'TT'];
>> str
str =
RRDETLMAXENTLAMTT
It is stored as single string size of 1x17
Then I tried
>> str=['RR'; 'DET' ;'LMAX'; 'ENT'; 'LAM'; 'TT'];
??? Error using ==> vertcat
CAT arguments dimensions are not consistent.
I want to store each word in single cell of a row vector... How to do this?

回答(1 个)

Use a cell array:
cstr = {'RR' 'DET' 'LMAX' 'ENT' 'LAM' 'TT'};
to access it:
cstr{1}

3 个评论

Is there any method to merge this cstr in first row of the matrix with the size 9x6 double type?
I tried
X=[ctr; Y];
where Y is 9x6 matrix
but error is
??? Error using ==> vertcat
CAT arguments dimensions are not consistent.
X = [cstr;num2cell(Y)]
In general char class and numeric class cannot be "merged" but you can use the a cell array or you can canvert the numeric type to char (see num2str)

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Characters and Strings 的更多信息

标签

提问:

2011-9-10

Community Treasure Hunt

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

Start Hunting!

Translated by