Cell Arrays to string

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 日

0 投票

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{:}]

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

質問済み:

2015 年 2 月 24 日

編集済み:

2015 年 2 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by