How to Add two strings
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
gmltn1212
el 22 de Mayo de 2020
Comentada: Mohammad Sami
el 22 de Mayo de 2020
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?
0 comentarios
Respuesta aceptada
Mohammad Sami
el 22 de Mayo de 2020
For a char array of the same length, you can do as follows.
A = 'abcde';
B = '12345';
C = reshape([A;B],1,[]);
2 comentarios
Mohammad Sami
el 22 de Mayo de 2020
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,[]);
Más respuestas (0)
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!