Effacer les filtres
Effacer les filtres

How to create a vector with the same string elements?

98 vues (au cours des 30 derniers jours)
osminbas
osminbas le 19 Avr 2012
Modifié(e) : Marco Gomez le 6 Juil 2023
Hello,
I am trying to create a vector with all the same string elements. When it is numeric, it is as easy as ones(10,1)*5, which gives a vector of "fives". How do you do the same thing with a string, say if I want a vector with all the elements of string 'hi'? Thank you!

Réponse acceptée

Sean de Wolski
Sean de Wolski le 19 Avr 2012
repmat('hi',[1 5]);
?
  2 commentaires
Diego Franco
Diego Franco le 30 Mar 2021
but this creates a cell for every letter you put in that string
Marco Gomez
Marco Gomez le 6 Juil 2023
Modifié(e) : Marco Gomez le 6 Juil 2023
try
repmat("hi",[1 5])';

Connectez-vous pour commenter.

Plus de réponses (1)

Luiz Guilherme Pancini
Luiz Guilherme Pancini le 27 Jan 2022
"hi" + strings(10,1)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by