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?

Réponses (1)

MKN
MKN le 24 Fév 2015
Modifié(e) : per isakson le 24 Fév 2015

0 votes

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 commentaires

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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange

Question posée :

le 24 Fév 2015

Modifié(e) :

le 24 Fév 2015

Community Treasure Hunt

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

Start Hunting!

Translated by