How do I convert a string to a single quotes string?

110 visualizaciones (últimos 30 días)
Brando Miranda
Brando Miranda el 17 de Oct. de 2017
Comentada: Guillaume el 26 de Sept. de 2018
I have a number N_train that I want to convert to a single quotes string (otherwise the title does not look as I want it):
title_name = ['Training data' string(N_train)]
though string returns a double quotes representation of the string for some reason. I tried making the first string double quotes but it doesn't fix it.
Is there a way to cast to single quotes strings in matlab?

Respuestas (2)

Guillaume
Guillaume el 17 de Oct. de 2017
single quote string is actually a char array. They were the only kind of strings available pre-R2016b. Anyway, to get a char array:
title_name = sprintf('Training Data %d', N_train);
or
title_name = compose('Training Data %d', N_train);
To get a string:
title_name = compose("Training Data %d", N_train);
  3 comentarios
Leo OfNature
Leo OfNature el 26 de Sept. de 2018
Yes, you can use the function char() to convert your string
Guillaume
Guillaume el 26 de Sept. de 2018
char will not convert a number to its char array representation (which is what is asked here).

Iniciar sesión para comentar.


Sean de Wolski
Sean de Wolski el 17 de Oct. de 2017
titleName = "Training data " + N_train
?

Categorías

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

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by