Need a space in strcat comand

3 vues (au cours des 30 derniers jours)
MINATI PATRA
MINATI PATRA le 26 Déc 2023
Commenté : Stephen23 le 26 Déc 2023
V = [1 2 3 4 5];
strcat ('R = ', strjoin(string( V),', '))
I got the following answer while running the above code
"R =1, 2, 3, 4, 5"
But i need (a white space after '=' sign)
"R = 1, 2, 3, 4, 5"
  1 commentaire
Stephen23
Stephen23 le 26 Déc 2023
The solution is already given in the STRCAT documentation:
V = 1:5;
strcat({'R = '},strjoin(string( V),', '))
ans = "R = 1, 2, 3, 4, 5"

Connectez-vous pour commenter.

Réponse acceptée

Dyuman Joshi
Dyuman Joshi le 26 Déc 2023
You can use strjoin again -
V = [1 2 3 4 5];
out1 = strjoin(["R =" strjoin(string(V),', ')])
out1 = "R = 1, 2, 3, 4, 5"
You can also add strings like this -
out2 = "R = " + strjoin(string(V),', ')
out2 = "R = 1, 2, 3, 4, 5"

Plus de réponses (1)

Image Analyst
Image Analyst le 26 Déc 2023
V = [1 2 3 4 5];
str = sprintf('R = %s', strjoin(string( V),', '))
str = 'R = 1, 2, 3, 4, 5'

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