Cell Arrays to string
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
MKN
am 24 Feb. 2015
Bearbeitet: per isakson
am 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 Kommentare
per isakson
am 24 Feb. 2015
Bearbeitet: per isakson
am 24 Feb. 2015
shorter
>> str = strjoin( cellData, ' ' )
str =
Matlab is a high level programming language
without space
>> str = strjoin( cellData, '' )
str =
Matlabisahighlevelprogramminglanguage
Siehe auch
Kategorien
Mehr zu Cell Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!