Filter löschen
Filter löschen

How to create a vector with the same string elements?

93 Ansichten (letzte 30 Tage)
osminbas
osminbas am 19 Apr. 2012
Bearbeitet: Marco Gomez am 6 Jul. 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!

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 19 Apr. 2012
repmat('hi',[1 5]);
?
  2 Kommentare
Diego Franco
Diego Franco am 30 Mär. 2021
but this creates a cell for every letter you put in that string
Marco Gomez
Marco Gomez am 6 Jul. 2023
Bearbeitet: Marco Gomez am 6 Jul. 2023
try
repmat("hi",[1 5])';

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

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

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by