MATLAB Answers

0

Cell Arrays to string

Asked by Bob Whiley on 24 Feb 2015
Latest activity Edited by per isakson
on 24 Feb 2015
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?

  0 Comments

Sign in to comment.

1 Answer

MKN
Answer by MKN
on 24 Feb 2015
Edited by per isakson
on 24 Feb 2015

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 Comments

per isakson
on 24 Feb 2015
shorter
>> str = strjoin( cellData, ' ' )
str =
Matlab is a high level programming language
without space
>> str = strjoin( cellData, '' )
str =
Matlabisahighlevelprogramminglanguage
Jos (10584)
on 24 Feb 2015
or, without spaces:
str = [cellData{:}]

Sign in to comment.