one two three four

2 visualizaciones (últimos 30 días)
James Knight
James Knight el 7 de Nov. de 2019
Comentada: Rena Berman el 12 de Dic. de 2019
I have two strings stored in a variable
EG
A='HELLO'
B='TEST'
I want to repeat B to make it the same length as A
EG
A='HELLOWORLD'
B='TESTTESTTE'
  3 comentarios
Guillaume
Guillaume el 7 de Nov. de 2019
If Thorsten hadn't posted an answer, I was going to close the question as it's a duplicate of https://www.mathworks.com/matlabcentral/answers/489791-repeat-the-value-of-a-variable-to-match-the-length-of-another-variable
Please don't waste people time by asking the same question twice.
Rena Berman
Rena Berman el 12 de Dic. de 2019
(Answers Dev) Restored edit

Iniciar sesión para comentar.

Respuesta aceptada

Thorsten
Thorsten el 7 de Nov. de 2019
Replicate B such that is is as long or longer than A, then cut it to the length of A;
B = repmat(B, 1, ceil(numel(A)/numel(B)));
B = B(1:numel(A));

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by