Putting quotes around the value of the variable

조회 수: 26 (최근 30일)
Adam Keller
Adam Keller . 2015년 8월 5일
답변: Adam Keller . 2015년 8월 5일
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.

채택된 답변

Adam Keller
Adam Keller 2015년 8월 5일
Worked with [ '''' x '''']

추가 답변 (1개)

Image Analyst
Image Analyst 2015년 8월 5일
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 =
The length of str1 is 1
str2 =
The length of str2 is 3
  댓글 수: 1
Adam Keller
Adam Keller 2015년 8월 5일
편집: Adam Keller 님. 2015년 8월 5일
That still didn't work for me, but I was able to solve it with ['''' x ''''], Thanks!

댓글을 달려면 로그인하십시오.


Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기


아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by