a way to use an empty char cell in inputdlg

Hi, and Merry Christmas at all
I need to use an inputdlg box with La Tex interpreter setted at
options.Interpreter = 'tex';
my prompts return from a for loop; so I used sprintf function:
for i=1:3
w = sprintf('\\alpha\ %d', i);
e = sprintf('A %d', i);
r = sprintf('\\theta\ %d', i);
q = sprintf('D %d', i);
z = sprintf('\\sigma\ %d (rot=0, prism=1)', i);
Title = sprintf('LINK %d',i);
prompt = {w,e,r,q,z};
numlines=1;
answer=inputdlg(prompt,Title,numlines,defans, options);
but, since I don't care default answer, I thought to assign it an empty space like:
defans = {'','','','',''};
or
defans = cell(1,5);
defans{1} = char(defans{1});
defans{2} = char(defans{1});
defans{3} = char(defans{1});
defans{4} = char(defans{1});
defans{5} = char(defans{1});
but in both cases matlab returns the same warning message:
Warning: Escape sequence ' ' is not valid. See 'help sprintf' for valid escape
sequences.
I think because '' form is an Escape sequence for sprintf() function.
How can I use the LaTex interpreter and an empty space as default answer without Warning Message returning ?

 채택된 답변

Jan
Jan 2012년 12월 29일
편집: Jan 2012년 12월 29일

0 개 추천

You need the string e.g. '\alpha 3'. You can create this by:
str = ['\alpha ', sprintf('%d', 3)]
or
str = sprintf('\\alpha %d', 3)
The backslash is the special character, which tells LaTeX that a command is following. The space is no valid format, such that '\ ' creates the shown error message.
The Backslash is a special character for sprintf also, e.g. '\n' means a line break. Therefore you have to escape it by another backslash, to get one backslash in the created string.
If this solves your problem, the question could be simplified:
How can I create a string, which is displayed by the LaTeX interpreter as "\alpha 3", where \alpha means the Greek character and the number is taken from a variable?

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 12월 24일

0 개 추천

backslash followed by space is not a valid sprintf() escape sequence.
Perhaps you need to use (e.g.) '\\\\alpha\\ %d'

댓글 수: 10

Marco
Marco 2012년 12월 24일
ok but I think warning message refers to '' in default answer
means
''
in default answer
Walter Roberson
Walter Roberson 2012년 12월 24일
Use your debugger and step through that code; you will be able to isolate where the warnings are coming from.
@Marco: Why do you think, that the problem appears in defans = {'','','','',''}? sprintf('\ ') reproduces the warning, such that I'm convinced, that Walter is right.
Another way to create your default answer:
defans = cell(1,5);
defans(:) = {''};
@Jan: Because I thought since warning message types ' ' form in itself so..but I was wrong.
@Walter: You are right. With command:
dbstop if warning
it indicates me
w = sprintf('\\alpha %d\', i);
I tried to type only
w = sprintf('\alpha %d', i);
but it doesn't interpret Tex string
Walter Roberson
Walter Roberson 2012년 12월 27일
Try '\\alpha %d\\ '
I tried with '\\alpha %d\\' and it returns another warning message:
Warning: Unable to interpret TeX string "\alpha 1\"
and does not interpret. Instead I tried with:
'\\alpha %d\'
and it interprets but retuns the same warning message:
Warning: Escape sequence '' is not valid. See 'help sprintf' for valid escape
sequences.
Jan
Jan 2012년 12월 28일
What about omitting the trailing slash?
Walter Roberson
Walter Roberson 2012년 12월 28일
What string is it that you would like to reach LaTex ?
Marco
Marco 2012년 12월 29일
I would like to interpret alpha (as greek symbol) with the number of for-loop index i by %d.

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

카테고리

도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

태그

질문:

2012년 12월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by