Borrar filtros
Borrar filtros

Putting quotes around the value of the variable

30 visualizaciones (últimos 30 días)
Adam Keller
Adam Keller el 5 de Ag. de 2015
Respondida: Adam Keller el 5 de Ag. de 2015
Hello I have a question regarding quotes, I have looked at other posts, but they do not match the question I have.
If I have a variable x = this_test_string
I would like to put a quote around this_test_string so it looks like the following 'this_test_string'
In my code, I don't know what x will be beforehand so I must have,
' (value of x) '
Is there a way to do this?
''' x ''' and '' x '' did not work.
Thanks

Respuesta aceptada

Adam Keller
Adam Keller el 5 de Ag. de 2015
Worked with [ '''' x '''']

Más respuestas (1)

Image Analyst
Image Analyst el 5 de Ag. de 2015
If I understood correctly, you want single quotes to be elements of your character array. You want the first and last element of the string to be a single quote character. See this:
% No quotes:
str1 = 'x'
fprintf('The length of str1 is %d\n\n', length(str1));
% String has single quote at start and end:
str2 = '''x'''
fprintf('The length of str2 is %d\n', length(str2));
str1 =
x
The length of str1 is 1
str2 =
'x'
The length of str2 is 3
  1 comentario
Adam Keller
Adam Keller el 5 de Ag. de 2015
Editada: Adam Keller el 5 de Ag. de 2015
That still didn't work for me, but I was able to solve it with ['''' x ''''], Thanks!

Iniciar sesión para comentar.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by