Cell Arrays to string

2 次查看(过去 30 天)
Bob Whiley
Bob Whiley 2015-2-24
If I have a long cell array, say a 1x120 cell (its arbitrary), each containing a different word like 'the' in one, and 'or' in the next. How can I combine the entire thing into one long string if possible?

回答(1 个)

MKN
MKN 2015-2-24
编辑:per isakson 2015-2-24
cellData = {'Matlab','is','a','high','level','programming','language'}; % Cell array
combinedString = [];
for i = 1:length(cellData)
combinedString = [combinedString cellData{i}]; % string
end
combinedString % display string
  2 个评论
per isakson
per isakson 2015-2-24
编辑:per isakson 2015-2-24
shorter
>> str = strjoin( cellData, ' ' )
str =
Matlab is a high level programming language
without space
>> str = strjoin( cellData, '' )
str =
Matlabisahighlevelprogramminglanguage
Jos (10584)
Jos (10584) 2015-2-24
or, without spaces:
str = [cellData{:}]

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by