필터 지우기
필터 지우기

Concatenate cells containing strings

조회 수: 44 (최근 30일)
AM
AM 2019년 1월 28일
댓글: madhan ravi 2019년 1월 28일
Hello,
I need to concatenate cells to obtain new strings within a new cell array.
For example I have cells A and B
A={'hello', 'hi', 'goodbye'};
B={' how are you', ' see you later'};
and want to obtain
message =
2×1 cell array
{'hello how are you' }
{'goodbye see you later'}
I manage to do this using loops
index=[1 3];
for i=1:length(index)
message{i}=[A{index(i)} B{i}];
end
Is there a more efficient way to do this? I never manage to figure out how to avoid loops, this is a short example but in reality I have much bigger cells.
Thank you in advance

채택된 답변

Fangjun Jiang
Fangjun Jiang 2019년 1월 28일
As long as you have two cell arrays with the same size, you can do this:
strcat(A(index),B)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by