Cell Arrays to string

조회 수: 4 (최근 30일)
Bob Whiley
Bob Whiley 2015년 2월 24일
편집: per isakson 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에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by