Generate a single string from a matrix (or cell)
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
H R
le 9 Déc 2017
Réponse apportée : Walter Roberson
le 9 Déc 2017
Hi. I have a vector A that is [1:5]' and also I have a string 'Hi'. (I just use a of length of 5 for simplicity, but can be large) (1) how can I generate a matrix B in such a way
Hi 1
Hi 2
Hi 3
Hi 4
Hi 5
(2) How can I convert matrix B to a 'single' string C as it is (i.e. after each Hi there is a space and after each number there is an enter (mew line character). In other words string C is
Hi 1
Hi 2
Hi 3
Hi 4
Hi 5
Note that Bi is a matrix or cell array, but C is only a string.
0 commentaires
Réponse acceptée
Walter Roberson
le 9 Déc 2017
With R2017a or later,
strjoin( "Hi " + (1:5).', newline )
For R2016b you can use
strjoin( string('Hi ') + (1:5).', newline )
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!