Hi, I am trying to add two strings:
A = 'a b c d e'
B = '1 2 3 4 5'
if I want to return a value 'a1b2c3d4e5', how should I set this up?

 채택된 답변

Mohammad Sami
Mohammad Sami 2020년 5월 22일

0 개 추천

For a char array of the same length, you can do as follows.
A = 'abcde';
B = '12345';
C = reshape([A;B],1,[]);

댓글 수: 2

gmltn1212
gmltn1212 2020년 5월 22일
whar about they are in different lengths?
Perhaps you may want to add some padding to make them the same length
A = 'abcde';
B = '1234567';
pad = ' ';
lA = length(A);
lB = length(B);
switch true
case lA < lB
A = [A repelem(pad,lB-lA)];
case lB < lA
B = [B repelem(pad,lA-lB)];
end
C = reshape([A;B],1,[]);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

질문:

2020년 5월 22일

댓글:

2020년 5월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by