How can I concatenate 3 strings using the value of a variable inbetween

5 visualizaciones (últimos 30 días)
Hi,
I have two strings:
string1='John'
string2='Maria'
I would like to write the following to an external file, called stringtext.txt
John,1,Maria
John,2,Maria
John,3,Maria
John,4,Maria
John,5,Maria
How can I do it in MATLAB?
I thank you in advance,
Best regards,

Respuesta aceptada

Walter Roberson
Walter Roberson el 5 de Sept. de 2021
string1='John'
string1 = 'John'
string2='Maria'
string2 = 'Maria'
string1 + "," + string(1:5).' + "," + string2
ans = 5×1 string array
"John,1,Maria" "John,2,Maria" "John,3,Maria" "John,4,Maria" "John,5,Maria"

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by